syntax = "proto3";

package com.wixpress.authorization.abac.dev;

import "google/api/annotations.proto";
import "com/wixpress/authorization/abac/management/Subject.proto";
import "wix/api/annotations.proto";

// flynt-disable missing-service-entity
service AbacAuthorizationDevService {
    option (wix.api.service_exposure) = PRIVATE;

    rpc ChangePolicyOwner (ChangePolicyOwnerRequest) returns (ChangePolicyOwnerResponse);

    rpc GetPoliciesScopesDiff (GetPoliciesScopeDiffsRequest) returns (GetPoliciesScopesDiffResponse);

    rpc ForceDeleteAssignments (ForceDeleteAssignmentsRequest) returns (ForceDeleteAssignmentsResponse);

    rpc UpdateSiteContextAssignments (UpdateSiteContextAssignmentsRequest) returns (UpdateSiteContextAssignmentsResponse);

    rpc GetPoliciesMissingSubPoliciesPermissions (GetPoliciesMissingSubPoliciesPermissionsRequest) returns (GetPoliciesMissingSubPoliciesPermissionsResponse) {
        option (google.api.http).get = "/v1/dev/policies/missing_permissions";
    }

    rpc fixBrokenTeamMembersAssignments(FixTeamMemberAssignmentsRequest) returns (EmptyResponse);

    rpc AssignPolicy(AssignPolicyRequest) returns (EmptyResponse);

    rpc HardDeleteStatement(HardDeleteStatementRequest) returns (HardDeleteStatementResponse);
}

message FixTeamMemberAssignmentsRequest {
    string user_id = 1;
    string account_id = 2;
}

message EmptyResponse { }


message ChangePolicyOwnerRequest {
    string policy_id = 1;
    string policy_owner_type = 2;
    string policy_owner_id = 3;
}

message ChangePolicyOwnerResponse {
}

message GetPoliciesScopeDiffsRequest {
    repeated string policy_ids = 1;
}

message GetPoliciesScopesDiffResponse {
    repeated PolicyPermissions policies_permissions = 1;

}

message ForceDeleteAssignmentsRequest {
    repeated string assignment_ids = 1;
}

message ForceDeleteAssignmentsResponse {
    bool is_deleted = 1;
}

message UpdateSiteContextAssignmentsRequest {
    string meta_site_id = 1;
    string old_owner_id = 2;
}

message UpdateSiteContextAssignmentsResponse {
    string results_info = 1;
}

message PolicyPermissions {
    string policy_id = 1;
    repeated string global_scopes = 2;
    repeated string other_scopes = 3;
    repeated string role_permissions = 4;
    repeated string scopes_permissions = 5;
    repeated string flattened_permissions = 6;
    repeated string missing_permissions_in_scopes = 7;
    repeated string missing_permissions_in_role_from_scopes = 8;
    repeated string missing_permissions_in_role_from_flattened = 9;
}

message GetPoliciesMissingSubPoliciesPermissionsRequest {
    repeated string notify_emails = 1;
}

message GetPoliciesMissingSubPoliciesPermissionsResponse {
    repeated PolicyMissingPermissions policies_missing_permissions = 1;
}

message PolicyMissingPermissions {
    string policy_id = 1;
    repeated MissingPermissions missing_permissions = 2;
}

message MissingPermissions {
    string policy_id = 1;
    repeated string permissions = 2;
}

message AssignPolicyRequest {
    // The subject to assign to policy to.
    com.wixpress.authorization.abac.management.Subject subject = 1;
    // The id of the policy to assign.
    string policy_id = 2;

    map<string, string> context_keys = 3;
}

message HardDeleteStatementRequest {
    string statement_id = 1;
}

message HardDeleteStatementResponse {
    bool success = 1;
}
