	syntax = "proto3";
package administrationservices;

// ==========================================
// 1. MENSAJES LEGACY & COMPARTIDOS
// ==========================================

message administrationservices{	
	string response =1;
}
message profiles{
	int32 idprofile=1;
	string profile=2;
}
message allprofiles{
	repeated profiles profiles=1;
}
message orgprofiles{
	int32 idprofiles=1;
	string profile=2;
	int32 idprofileorganization=3;
	int32 idorg=4;
	string jsonservices=5;
	string nameorg=6;
}
message allorgprofiles{
	repeated orgprofiles  orgprofiles=1;
}
message userprofiles{
	int32 idprofile=1;
	string profile=2;
	int32 org_id=3;
	int32 id_user_profile=4;
	int32 iduser=5;
	int32 public_id=6;
	string username=7;
	string jsonservices=8;
}
message alluserprofiles{
	repeated userprofiles userprofile=1;
}
message userVCD{
	int32 userVCDId=1;
	string username=2;
	int32 org_id=3;
	int32 public_id=4;
	string password=5;
}
message orgVCD{
	int32 OrgVcdId=1;
	string name=2;
	string host=3;
	string api_version=4;
}
message UsersVCD{
	repeated userVCD users=1;
}
message orgsVCD{
	repeated orgVCD orgs=1;
}
message fieldvdc{
	int32 id=1;
	string name=2;
	string urn_id=3;
	string subscription_id=4;
	int32 org_id=5;
}
message allfieldsvdc{
	repeated fieldvdc fieldvdc=1;
}
message MenuComponent {
	int32 idmenu_component = 1;
	string component_name = 2;
	string component_path = 3;
	string description=4;
}
message MenuComponentAccessInfo {
	int32 menuComponentId = 1;
	string componentName = 2;
}
message MenuComponentAccess {
	int32 idmenu_component = 1;
	string component_name = 2;
	bool can_view = 3;
	bool can_edit = 4;
	bool can_delete = 5;
}
message Service {
	int32 serviceId = 1;
	string serviceName = 2;
}
message Role {
	int32 roleId = 1;
	string roleName = 2;
}
message UserAccessInfo {
	int32 userId = 1;
	string username = 2;
	int32 organizationId = 3;
	string organizationName = 4;
	repeated Role roles = 5;
	repeated MenuComponentAccessInfo menuComponents = 6;
	repeated Service services = 7;
}

// --- MENSAJES ACTUALIZADOS (Con todas las columnas) ---

message ServiceInfo {
	int32 servicesid = 1;
	string name = 2;
    int32 product_type_id = 3;
    string events_ids = 4;
    string description = 5;
    string form_tmplt = 6;
    bool active = 7;
    string last_update = 8; // Fecha como string ISO
    int32 base_price = 9;
    string service_logo_url = 10;
    bool visible = 11;
}
message ProductTypeInfo {
		int32 id = 1; 
		string product_name = 2; // Antes name
    string product_dsc = 3;
    bool is_available = 4;
    string steps = 5;
    string identification_key = 6;
	}
message RoleInfo{
	int32 idrole = 1;
	int32 idorganization = 2;
	string role_name = 3;
	string description = 4;
	string last_modified = 5;
	int32 created_by = 6;
	repeated MenuComponentAccess menu_components = 7;
	repeated ServiceInfo services = 8;
	repeated ProductTypeInfo products = 9;
}
message all_roles{
	repeated RoleInfo response=1;
}

message PingResponse {
  bool is_alive = 1;
  string version = 2;
  string server_time = 3;
}
message EmptyRequest {}
// ==========================================
// 2. MENSAJES DE REQUEST/RESPONSE LEGACY
// ==========================================

message SetNewExpositionCategoryRequest{
 string exposition_category_name=1;
}
message GetProfilesRequest{
	int32 idprofile=1;
	int32 idorg=2;
	int32 iduser=3;
	int32 public_id=4;
}
message SetNewProfile{
 string nameProfile=1;
}
message SetUserVCDRequest{
	string username=2;
	string email=3;
	int32 orgid=4;
}
message GetUserVCDRequest{
	string user_name=1;
	int32 public_id=2;
	int32 user_id=3;
	int32 org_id=4;
}
message	GetOrgVCDRequest{
	string name=1;
	int32 org_id=2;
}
message SetOrgVCDRequest {
	string name=2;
	string host=3;
	string api_version=4;
}
message SetContractedServicesRequest{
	int32 user_id=1;
	int32 backup_scheduled_id=2; 
	int32 plan_id=3;
	int32 firewall_id=4;
	int32 vdc_vcd_id=5;
}
message getfieldsvdcRequest{
	int32 vdc_id=1;
	int32 org_id=2;
	string urn_id=3;
}
message setfieldsvdcRequest{
	int32 vdc_id=1;	
	string name=2;
	string urn_id=3;
	int32 subscription_id=4;
	int32 org_id=5;
	bool active=6;
}
message insertfieldsvdcRequest{
	string name=1;
	string urn_id=2;
	int32 subscription_id=3;
	int32 org_id=4;		
}
message SetRoleRequest {
	int32 idrole = 1;
	int32 idorganization = 2;
	string role_name = 3;
	string description = 4;
	int32 created_by = 5;
	int32 idmenu_component = 6;
	bool can_view = 7;
	bool can_edit = 8;
	bool can_delete = 9;
	string json_services = 10;
	bool active = 11;
}
message SetMenuComponentRequest {
	int32 idmenu_component = 1;
	string component_name = 2;
	string description = 3;
	string component_path = 4;
}
message GetAllMenuComponentsRequest {
	string component_name_filter = 1; 
	int32 idmenu_component_filter = 2;
}
message GetUserAccessInfoRequest {
	int32 userId = 1;
	int32 organizationId = 2;
	int32 idrole=3;
}
message SetUserRoleRequest {
	int32 user_id = 1;
	int32 idrole = 2;
	int32 idorganization = 3;
	int32 assigned_by = 4;
}
message GetRoleInfoRequest {
	int32 idrole = 1; 
	int32 idorganization = 2;
}

message SetNewExpositionCategoryResponse{
 administrationservices response=1;
}
message GetProfileListResponse{
	repeated profiles response=1;
}
message GetUserProfileListResponse{
	repeated userprofiles response=1;
}
message SetUserVCDResponse{
	administrationservices response=1;
}
message GetOrgVCDResponse {
	repeated orgVCD response=1;
}
message SetOrgVCDResponse{
	administrationservices response=1;
}
message SetContractedServicesResponse{
	administrationservices response=1;
}
message getfieldsvdcResponse{
	repeated fieldvdc response=1;
}
message setfieldsvdcResponse {
	administrationservices response=1;
}
message insertfieldsvdcResponse {
	administrationservices response=1;
}
message ProfileResponse {
  bool success = 1;
  string message = 2;
}
message SetRoleResponse {
	bool success = 1;
	string message = 2;
}
message SetMenuComponentResponse {
	bool success = 1;
	string message = 2;
}
message GetAllMenuComponentsResponse {
	repeated MenuComponent components = 1;
}
message GetUserAccessInfoResponse {
	repeated UserAccessInfo userAccessInfo = 1;
}
message SetUserRoleResponse {
	bool success = 1;
	string message = 2;
}
message GetRoleInfoResponse {
	repeated RoleInfo response = 1;
}

// ==========================================
// 3. MENSAJES NUEVOS: LÓGICA DE NEGOCIO
// ==========================================

message GetUserPermissionsRequest {
  int32 user_id = 1;
}
message GetUserPermissionsResponse {
  int32 user_id = 1;
  string username = 2;
  string tenant = 3;
  string tipo_nube = 4;
  string permission_data_json = 5;
  bool is_default_profile = 6;
}


// ==========================================
// 4. MENSAJES NUEVOS: CRUD PERFILES
// ==========================================

message ProfileData {
  int32 profile_id = 1;
  // organization_id eliminado
  string name = 3;
  string identifier = 4;
  bool is_active = 5;
  string permission_data_json = 6;
}

message ProfileDataTable {
  int32 profile_id = 1;
  string name = 3;
  string identifier = 4;
  bool is_active = 5;
}

message CreateProfileRequest {
  string name = 1;
  string identifier = 3;
  bool is_active = 4;
  string permission_data_json = 5; 
}
message GetProfileByIdRequest {
  int32 profile_id = 1;
}
message UpdateProfileRequest {
  int32 profile_id_to_update = 1;
  string name = 2;
  string identifier = 3;
  bool is_active = 4;
  string new_permission_data_json = 5;
}
message DeleteProfileRequest {
  int32 profile_id = 1;
}

// Paginado
message GetPaginatedProfilesRequest {
  int32 page_size = 1;
  int32 current_page = 2;
  string search_term = 3; 
  map<string, string> where_filters = 4; 
}

// Nuevo request para GetAll (sin paginación)
message GetAllProfilesRequest {
    string search_term = 1;
    map<string, string> where_filters = 2;
}

message GetPaginatedProfilesResponse {
  repeated ProfileData records = 1;
  int32 total_records = 2;
}

message AssignProfileRequest {
    int32 user_id = 1;
    int32 profile_id = 2;
}
message RemoveProfileRequest {
    int32 user_id = 1;
    int32 profile_id = 2;
}

message CreateProfileResponse {
  bool success = 1;
  string message = 2;
  int32 inserted_id = 3;
}
message UpdateProfileResponse {
  bool success = 1;
  string message = 2;
}
message DeleteProfileResponse {
  bool success = 1;
  string message = 2;
}
message AssignProfileResponse {
    bool success = 1;
    string message = 2;
}
// --- NUEVO MENSAJE DE RESPUESTA (Contenedor de la lista) ---
// Este es el mensaje clave que tu código C# está intentando devolver
message GetAllProfilesResponse {
  repeated ProfileDataTable profiles = 1;
}

// ==========================================
// 5. DEFINICIÓN DE SERVICIOS
// ==========================================

service administrationService {
    // --- Legacy ---
	rpc SetNewExpositionCategory (SetNewExpositionCategoryRequest) returns (SetNewExpositionCategoryResponse){};		
	rpc setRoleAndAccess (SetRoleRequest) returns (SetRoleResponse);
	rpc setMenuComponent (SetMenuComponentRequest) returns (SetMenuComponentResponse);
	rpc getAllMenuComponents (GetAllMenuComponentsRequest) returns (GetAllMenuComponentsResponse);
	rpc getUserAccessInfo(GetUserAccessInfoRequest) returns (GetUserAccessInfoResponse);
	rpc setUserRole (SetUserRoleRequest) returns (SetUserRoleResponse);
	rpc getRoleInfo (GetRoleInfoRequest) returns (all_roles);

    
}

service ProfileService {
	// --- Nueva Lógica de Negocio ---
    rpc GetUserPermissions(GetUserPermissionsRequest) returns (GetUserPermissionsResponse);
   
		//-- HEALTH CHECK ---
		rpc Ping(EmptyRequest) returns (PingResponse);
    // --- CRUD Genérico ---   
    rpc GetProfilesById(GetProfileByIdRequest) returns (ProfileData);      
    rpc GetAllProfiles(GetAllProfilesRequest) returns (GetAllProfilesResponse);    
    // Asignaciones
    rpc AssignProfileToUser(AssignProfileRequest) returns (AssignProfileResponse);
    rpc RemoveProfileFromUser(RemoveProfileRequest) returns (AssignProfileResponse);
}
// --- SERVICIO 2: INTERNO / OCULTO EN POSTMAN ---
// (Este contiene Create, Update, Delete)
//service ProfileInternalService {
//   rpc Create(CreateProfileRequest) returns (CreateProfileResponse);
// rpc Update(UpdateProfileRequest) returns (UpdateProfileResponse);
//  rpc Delete(DeleteProfileRequest) returns (DeleteProfileResponse);
// Búsqueda Paginada
// rpc GetPaginated(GetPaginatedProfilesRequest) returns (GetPaginatedProfilesResponse);
//}
