syntax = "proto3";

import "Proto/common/user.proto";

import "google/protobuf/wrappers.proto";
import "google/protobuf/empty.proto";

package laborato.mesh.service;

// Stream policy assigment sync
service UserControlService {
    rpc UserControlStream(stream UserControlAgentMessage) returns (stream UserControlMasterMessage);
    rpc SetUserEnabled(FeedbackEnableUserRequest) returns (google.protobuf.Empty);
}

message FeedbackEnableUserRequest {
    string sam_account_name = 1;
    bool enable = 2;
}

message UserControlAgentMessage {
  string agent_id = 1;
}

message UserControlMasterMessage {
  oneof payload {
    UserCreateCommand create = 1;
    UserUpdateCommand update = 2;
    UserDeleteCommand delete = 3;
    UserEnableCoomand enable_disable = 4;
    UserSetPasswordCommand set_password = 5;
    UserUnlockCommand unlock = 6;
    UserExpirePasswordCommand expire_password = 7;
    UserSetAccountExpirationCommand set_account_expiration = 8;
    CreateGroupCommand create_group = 9;
    DeleteGroupCommand delete_group = 10;
    AddUserToGroupCommand add_user_to_group = 11;
    RemoveUserFromGroupCommand remove_user_from_group = 12;
    UpdateGroupCommand update_group = 13;
  }
}

message UserCreateCommand {
    laborato.common.user.UserRequest request = 1;
}

message UserUpdateCommand {
    string sam_id = 1;
    laborato.common.user.UserRequest request = 2;
}

message UserDeleteCommand {
    string sam_id = 1;
}

message UserEnableCoomand {
    string sam_id = 1;
    bool enable = 2;
}

message UserSetPasswordCommand {
    string sam_id = 1;
    string new_password = 2;
}

message UserUnlockCommand {
    string sam_id = 1;
}

message UserExpirePasswordCommand {
    string sam_id = 1;
}

message UserSetAccountExpirationCommand {
    string sam_id = 1;
    google.protobuf.StringValue account_expiration_date = 2; // ISO 8601
}

message CreateGroupCommand {
    string sam_group_name = 1;
    google.protobuf.StringValue description = 2;
}

message UpdateGroupCommand {
    string current_sam_group_name = 1;
    string new_sam_group_name = 2;
    google.protobuf.StringValue description = 3;
}

message DeleteGroupCommand {
    string sam_group_name = 1;
}

message AddUserToGroupCommand {
    string sam_group_name = 1;
    string sam_account_name = 2;
}

message RemoveUserFromGroupCommand {
    string sam_group_name = 1;
    string sam_account_name = 2;
}