syntax = "proto3";

package com.wixpress.authorization.abac.management.events;

import "wix/api/validations.proto";
import "com/wixpress/authorization/abac/management/Subject.proto";
import "com/wixpress/authorization/abac/Context.proto";
import "com/wixpress/authorization/abac/management/Conditions.proto";
import "com/wixpress/authorization/abac/management/Policy.proto";
import "google/protobuf/wrappers.proto";
import "wix/api/entity.proto";

message PolicyAssignedToTeamMember {
    string user_id = 1 [(wix.api.format) = GUID];
    string account_id = 2 [(wix.api.format) = GUID];
}

message PolicyRemovedFromTeamMember {
    string user_id = 1 [(wix.api.format) = GUID];
    string account_id = 2 [(wix.api.format) = GUID];
}

message PolicyAssignedToContributor {
    string account_id = 1 [(wix.api.format) = GUID];
    string meta_site_id = 2 [(wix.api.format) = GUID];
    repeated string policy_ids = 3;
}

message PolicyRemovedFromContributor {
    string account_id = 1 [(wix.api.format) = GUID];
    string meta_site_id = 2 [(wix.api.format) = GUID];
    repeated string policy_ids = 3;
}

message PolicyUpdatedForContributor {
    string account_id = 1 [(wix.api.format) = GUID];
    string meta_site_id = 2 [(wix.api.format) = GUID];
    repeated string old_policy_ids = 3;
    repeated string new_policy_ids = 4;
}

message PolicyAssignmentsUpdated {
    oneof event {
        PolicyAssigned policy_assigned = 1;
        PolicyUnassigned policy_unassigned = 2;
        PolicyAssignmentUpdated policy_assignment_updated = 3;
    }
}

message PolicyAssigned {
    com.wixpress.authorization.abac.management.Subject subject = 1;
    repeated PolicyAssignment assignment = 2;
}

message PolicyUnassigned {
    com.wixpress.authorization.abac.management.Subject subject = 1;
    repeated PolicyAssignment assignment = 2;
}

message PolicyAssignmentUpdated {
    com.wixpress.authorization.abac.management.Subject subject = 1;
    repeated PolicyAssignment from_assignment = 2;
    repeated PolicyAssignment to_assignment = 3;
}

message PolicyAssignment {
    string policy_id = 1;
    ResourcePath resource = 2;
    PolicyCondition condition = 3;
    google.protobuf.StringValue assignment_id = 4;
}

message ResourcePolicyAssignmentEvent {
    oneof event {
        ResourcePolicyAssigned policy_assigned = 1;
        ResourcePolicyUnassigned policy_unassigned = 2;
        ResourcePolicyReplaced policy_replaced = 3;
    }
}

message ResourcePolicyAssigned {
    com.wixpress.authorization.abac.management.Subject subject = 1;
    ResourcePath resource = 2;
    string policy_id = 3[deprecated=true];
    AssignmentInfo assignment = 4;
}

message ResourcePolicyUnassigned {
    com.wixpress.authorization.abac.management.Subject subject = 1;
    ResourcePath resource = 2;
    //the policy id that was removed
    string policy_id = 3[deprecated=true];
    // The assignment info - policy id and condition of the unassigned policy
    AssignmentInfo assignment = 4;
    //info about the remaining assignments on the resource
    repeated AssignmentInfo remaining_assignments_info = 5;
}

message AssignmentInfo {
    string policy_id = 1;
    repeated PolicyCondition conditions = 2;
}

message ResourcePolicyReplaced {
    com.wixpress.authorization.abac.management.Subject subject = 1;
    ResourcePath resource = 2;
    repeated string from_policy_ids = 3[deprecated=true];
    repeated string to_policy_ids = 4[deprecated=true];
    repeated AssignmentInfo from_assignments = 5;
    repeated AssignmentInfo to_assignments = 6;
}

message ResourcePath {
    google.protobuf.StringValue organization = 1;
    google.protobuf.StringValue account = 2;
    google.protobuf.StringValue site = 3;
    Resource resource = 4;
}

message PolicyAuthorizationDataUpdated {
    string policy_id = 1;
    repeated PolicyStatement from_policy_statements = 2;
    repeated PolicyStatement to_policy_statements = 3;
    PolicyType policy_type = 4;
    PolicyOwner policy_owner = 5;
}

message PolicyCreated {
    option (.wix.api.entity) = {
        fqdn: "wix.identity.authorization.v1.policy_created"
        segment: USERS
    };
    string id = 1[(wix.api.minLength) = 1, (wix.api.maxLength) = 100];
}
