syntax = "proto3";

package admin;

service AdminService {
  rpc ListUsers (ListUsersRequest) returns (ListUsersResponse);
  rpc ListBotAccounts (ListUsersRequest) returns (ListUsersResponse);
  rpc UpdateUserProfile (UpdateUserRequest) returns (AdminUser);
  rpc ResetPassword (ResetPasswordRequest) returns (AdminUser);
  rpc SuspendUser (UserIdRequest) returns (AdminUser);
  rpc SetSuperAdmin (SetSuperAdminRequest) returns (AdminUser);
  rpc SetUserVerification (SetUserVerificationRequest) returns (AdminUser);
  rpc ListVerificationIcons (Empty) returns (ListVerificationIconsResponse);
  rpc GetUserSignInHistory (GetUserInsightsRequest) returns (UserSignInHistoryResponse);
  rpc GetUserActivity (GetUserInsightsRequest) returns (UserActivityResponse);
  rpc ListUserChatRooms (GetUserInsightsRequest) returns (UserChatRoomsResponse);
  rpc ListUserChatMessages (ListUserChatMessagesRequest) returns (UserChatMessagesResponse);
  rpc SearchUserChatMessages (SearchUserChatMessagesRequest) returns (UserChatMessageSearchResponse);
  rpc AdminDeleteChatMessage (AdminDeleteChatMessageRequest) returns (Empty);
}

message Empty {}

message ListUsersRequest {
  optional string search = 1;
}

message UserIdRequest {
  string userId = 1;
}

message UpdateUserRequest {
  string userId = 1;
  optional string displayName = 2;
  optional string email = 3;
  optional string phone = 4;
  optional string backupEmail = 5;
  optional string backupPhone = 6;
  optional string status = 7;
}

message ResetPasswordRequest {
  string userId = 1;
  string newPassword = 2;
}

message SetSuperAdminRequest {
  string actorUserId = 1;
  string userId = 2;
  bool isSuperAdmin = 3;
}

message SetUserVerificationRequest {
  string actorUserId = 1;
  string userId = 2;
  bool isVerified = 3;
  optional string verificationIcon = 4;
}

message VerificationIconOption {
  string slug = 1;
  string name = 2;
}

message ListVerificationIconsResponse {
  repeated VerificationIconOption icons = 1;
}

message AdminUser {
  string id = 1;
  optional string email = 2;
  optional string phone = 3;
  optional string backupEmail = 4;
  optional string backupPhone = 5;
  string displayName = 6;
  optional string username = 7;
  bool isSuperAdmin = 8;
  string status = 9;
  string createdAt = 10;
  repeated string roles = 11;
  repeated string directPermissions = 12;
  bool isVerified = 13;
  optional string verificationIcon = 14;
  bool isBot = 15;
  optional string linkedBotUsername = 16;
  optional bool isSystemBot = 17;
}

message ListUsersResponse {
  repeated AdminUser users = 1;
}

message GetUserInsightsRequest {
  string userId = 1;
  optional string search = 2;
  optional int32 limit = 3;
  optional int32 offset = 4;
  optional string dateFrom = 5;
  optional string dateTo = 6;
}

message AdminInsightsPeriodMeta {
  int32 retentionDays = 1;
  string periodFrom = 2;
  string periodTo = 3;
}

message AdminSignInEvent {
  string id = 1;
  bool success = 2;
  optional string reason = 3;
  optional string ipAddress = 4;
  optional string userAgent = 5;
  optional string deviceName = 6;
  string createdAt = 7;
}

message UserSignInHistoryResponse {
  int32 total = 1;
  repeated AdminSignInEvent events = 2;
  optional AdminInsightsPeriodMeta meta = 3;
  optional int32 retentionDays = 4;
  optional string periodFrom = 5;
  optional string periodTo = 6;
}

message UserActivityItem {
  string id = 1;
  string action = 2;
  string title = 3;
  optional string detail = 4;
  optional string entityType = 5;
  optional string entityId = 6;
  string createdAt = 7;
}

message UserActivityResponse {
  int32 total = 1;
  repeated UserActivityItem items = 2;
  optional AdminInsightsPeriodMeta meta = 3;
  optional int32 retentionDays = 4;
  optional string periodFrom = 5;
  optional string periodTo = 6;
}

message AdminChatRoomMember {
  string id = 1;
  string displayName = 2;
}

message AdminChatLastMessage {
  string id = 1;
  string senderName = 2;
  string preview = 3;
  string createdAt = 4;
}

message AdminChatRoomSummary {
  string id = 1;
  string type = 2;
  string name = 3;
  string groupId = 4;
  string groupName = 5;
  int32 memberCount = 6;
  int32 messageCount = 7;
  repeated AdminChatRoomMember members = 8;
  optional AdminChatLastMessage lastMessage = 9;
  string joinedAt = 10;
}

message UserChatRoomsResponse {
  int32 total = 1;
  repeated AdminChatRoomSummary rooms = 2;
  optional AdminInsightsPeriodMeta meta = 3;
  optional int32 retentionDays = 4;
  optional string periodFrom = 5;
  optional string periodTo = 6;
}

message ListUserChatMessagesRequest {
  string userId = 1;
  string roomId = 2;
  optional string search = 3;
  optional int32 limit = 4;
  optional string beforeMessageId = 5;
  optional string dateFrom = 6;
  optional string dateTo = 7;
}

message SearchUserChatMessagesRequest {
  string userId = 1;
  string search = 2;
  optional int32 limit = 3;
  optional int32 offset = 4;
  optional string dateFrom = 5;
  optional string dateTo = 6;
}

message AdminChatMessage {
  string id = 1;
  string senderId = 2;
  string senderName = 3;
  string type = 4;
  optional string content = 5;
  string preview = 6;
  bool isEncrypted = 7;
  bool isDeleted = 8;
  string createdAt = 9;
  optional string editedAt = 10;
  optional string roomId = 11;
  optional string roomName = 12;
  optional string groupName = 13;
  optional string storageKey = 14;
  optional string mimeType = 15;
  optional string metadataJson = 16;
}

message AdminChatRoomContext {
  string id = 1;
  string name = 2;
  string type = 3;
  string groupName = 4;
}

message UserChatMessagesResponse {
  optional AdminChatRoomContext room = 1;
  repeated AdminChatMessage messages = 2;
  optional AdminInsightsPeriodMeta meta = 3;
  optional int32 retentionDays = 4;
  optional string periodFrom = 5;
  optional string periodTo = 6;
}

message UserChatMessageSearchResponse {
  int32 total = 1;
  repeated AdminChatMessage messages = 2;
  optional AdminInsightsPeriodMeta meta = 3;
  optional int32 retentionDays = 4;
  optional string periodFrom = 5;
  optional string periodTo = 6;
}

message AdminDeleteChatMessageRequest {
  string actorUserId = 1;
  string messageId = 2;
}
