/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

syntax = "proto3";

option java_multiple_files = true;
package org.apache.custos.sharing.service;

import "SharingModel.proto";

option go_package = "./pb";




message EntityRequest {
    string client_id = 1;
    int64 tenant_id = 2;
    org.apache.custos.sharing.core.Entity entity = 3;
    string client_sec = 4;
}

message EntityTypeRequest {
    string client_id = 1;
    int64 tenant_id = 2;
    org.apache.custos.sharing.core.EntityType entity_type = 3;
    string client_sec = 4;
}


message PermissionTypeRequest {
    string client_id = 1;
    int64 tenant_id = 2;
    org.apache.custos.sharing.core.PermissionType permission_type = 3;
    string client_sec = 4;
}




message SearchRequest {
    string client_id = 1;
    int64 tenant_id = 2;
    string owner_id = 3;
    int32 offset = 4;
    int32 limit = 5;
    repeated org.apache.custos.sharing.core.SearchCriteria search_criteria = 6;
    string client_sec = 7;
    repeated string associating_ids = 8;
    bool search_perm_bottom_up=9;
}

message PermissionRequest {
    string client_id = 1;
    int64 tenant_id = 2;
    org.apache.custos.sharing.core.Entity entity = 3;
    org.apache.custos.sharing.core.PermissionType permission_type = 4;
    string client_sec = 5;
}

message SharingRequest {
    string client_id = 1;
    int64 tenant_id = 2;
    org.apache.custos.sharing.core.Entity entity = 3;
    org.apache.custos.sharing.core.PermissionType permission_type = 4;
    repeated string owner_id = 5;
    bool cascade = 6;
    string client_sec = 7;
    string shared_by = 8;
}

message SharesFilteringRequest {
    string client_id = 1;
    int64 tenant_id = 2;
    repeated string owner_id = 5;
    bool cascade = 6;
    string client_sec = 7;
}

message Status {
    bool status = 1;
}

message EntityTypes {
    repeated org.apache.custos.sharing.core.EntityType types = 1;
}

message PermissionTypes {
    repeated org.apache.custos.sharing.core.PermissionType types = 1;
}

message Entities {
    repeated org.apache.custos.sharing.core.Entity entity_array = 1;
}

message SharedOwners {
    repeated string owner_ids = 1;
}

message GetAllDirectSharingsResponse {
    repeated org.apache.custos.sharing.core.SharingMetadata  shared_data = 1;
}

message GetAllSharingsResponse {
    repeated org.apache.custos.sharing.core.SharingMetadata  shared_data = 1;
}



service SharingService {


    rpc createEntityType (EntityTypeRequest) returns (Status);
    rpc updateEntityType (EntityTypeRequest) returns (Status);
    rpc deleteEntityType (EntityTypeRequest) returns (Status);
    rpc getEntityType (EntityTypeRequest) returns (org.apache.custos.sharing.core.EntityType);
    rpc getEntityTypes (SearchRequest) returns (EntityTypes);

    rpc createPermissionType (PermissionTypeRequest) returns (Status);
    rpc updatePermissionType (PermissionTypeRequest) returns (Status);
    rpc deletePermissionType (PermissionTypeRequest) returns (Status);
    rpc getPermissionType (PermissionTypeRequest) returns (org.apache.custos.sharing.core.PermissionType);
    rpc getPermissionTypes (SearchRequest) returns (PermissionTypes);

    rpc createEntity (EntityRequest) returns (Status);
    rpc updateEntity (EntityRequest) returns (Status);
    rpc isEntityExists (EntityRequest) returns (Status);
    rpc getEntity (EntityRequest) returns (org.apache.custos.sharing.core.Entity);
    rpc deleteEntity (EntityRequest) returns (Status);
    rpc searchEntities (SearchRequest) returns (Entities);



    rpc getListOfSharedUsers (SharingRequest) returns (SharedOwners);
    rpc getListOfDirectlySharedUsers (SharingRequest) returns (SharedOwners);
    rpc getListOfSharedGroups (SharingRequest) returns (SharedOwners);
    rpc getListOfDirectlySharedGroups (SharingRequest) returns (SharedOwners);
    rpc getAllDirectSharings (SharingRequest) returns (GetAllDirectSharingsResponse);
    rpc getAllSharings (SharingRequest) returns (GetAllSharingsResponse);

    rpc shareEntityWithUsers (SharingRequest) returns (Status);
    rpc shareEntityWithGroups (SharingRequest) returns (Status);
    rpc revokeEntitySharingFromUsers (SharingRequest) returns (Status);
    rpc revokeEntitySharingFromGroups (SharingRequest) returns (Status);
    rpc userHasAccess (SharingRequest) returns (Status);


}