syntax = "proto3";

package com.wixpress.authorization.abac;

import "com/wixpress/authorization/abac/Context.proto";
import "wix/api/entity.proto";

message ResourceAttributeUpdate {
    FullNameResource full_name_resource = 1;
    ResourceAttributeUpdateEvent update_event = 2;
}

message ResourceAttributeUpdateEvent {
    oneof event {
        SetAttribute set_attribute = 1;
        UnsetAttribute unset_attribute = 2;
        UpdateAttribute update_attribute = 3;
    }
}

message ResourcesAttributeUpdatedEvent {
    FullNameResource full_name_resource = 1;
    string attribute_type = 2;
    repeated string previous_attribute_values = 3;
    repeated string current_attribute_values = 4;
}

message SetAttribute {
    Attribute attribute = 1;
}

message UnsetAttribute {
    Attribute attribute = 1;
}

message UpdateAttribute {
    Attribute old_attribute = 1;
    Attribute new_attribute = 2;
}

message BulkResourceAttributeUpdateRequest {
    repeated FullNameResource full_name_resources = 1;
    ResourceAttributeUpdateEvent update_event = 2;
}

message BulkResourceAttributeUpdateResponse {
    repeated AttributeUpdateResourceResult resource_update_results = 1;
}

message AttributeUpdateResourceResult {
    FullNameResource full_name_resource = 1;
    UpdateResult result = 2;
}

message UpdateResourcesWithAttributeMessage {
    AttributesOperator operator = 1;
    string replacement_attribute_value = 2;
}

message BulkUpdateResourcesWithAttributeRequest {
    repeated AttributesOperator operators = 1;
    string replacement_attribute_value = 2;
}

message BulkUpdateResourcesWithAttributeResponse {
    repeated AttributeUpdateWithOperatorResult operator_update_results = 1;
}

message AttributeUpdateWithOperatorResult {
    AttributesOperator operator = 1;
    UpdateResult result = 2;
}

message UpdateResult {
    oneof result {
        UpdateSuccess success = 1;
        UpdateFailure failure = 2;
    }
}

message UpdateSuccess {}

message UpdateFailure {
    string error_message = 1;
}

message AttributesOperator {
    oneof operators {
        ExactMatch exact_match = 1;
        StartsWith starts_with = 2;
    }
}

message ExactMatch {
    Attribute attribute = 1;
}

message StartsWith {
    Attribute attribute = 1;
}

message Attribute {
    option (.wix.api.entity) = {
        fqdn: "wix.identity.authorization.v1.attribute"
        segment: USERS
    };
    string attribute_type = 1;
    string attribute_value = 2;
}
