syntax = "proto3";

package admin;

import "google/protobuf/timestamp.proto";

// ---------------------------------------------------------------------------
// Session entities
// ---------------------------------------------------------------------------

message UserSession {
  string session_id = 1;
  string user_id = 2;
  string workspace_id = 3;
  optional string ip_address = 4;
  optional string user_agent = 5;
  google.protobuf.Timestamp connected_at = 6;
  google.protobuf.Timestamp last_heartbeat = 7;
}

message SessionInfo {
  string user_id = 1;
  uint32 session_count = 2;
  repeated string workspaces = 3;
  optional UserSession latest_session = 4;
}

enum OnlineStatus {
  ONLINE_STATUS_UNSPECIFIED = 0;
  ONLINE_STATUS_ONLINE = 1;
  ONLINE_STATUS_IDLE = 2;
  ONLINE_STATUS_OFFLINE = 3;
}

// ---------------------------------------------------------------------------
// Requests & Responses
// ---------------------------------------------------------------------------

message ListWorkspaceSessionsRequest {
  string workspace_id = 1;
}
message ListWorkspaceSessionsResponse {
  repeated UserSession sessions = 1;
}

message ListUserSessionsRequest {
  string user_id = 1;
}
message ListUserSessionsResponse {
  repeated UserSession sessions = 1;
}

message KickUserFromWorkspaceRequest {
  string user_id = 1;
  string workspace_id = 2;
}
message KickUserFromWorkspaceResponse {
  uint32 kicked_count = 1;
}

message KickUserRequest {
  string user_id = 1;
}
message KickUserResponse {
  uint32 kicked_count = 1;
}

message GetUserStatusRequest {
  string user_id = 1;
}
message GetUserStatusResponse {
  OnlineStatus status = 1;
}

message GetUserInfoRequest {
  string user_id = 1;
}
message GetUserInfoResponse {
  optional SessionInfo info = 1;
}

message GetWorkspaceOnlineUsersRequest {
  string workspace_id = 1;
}
message GetWorkspaceOnlineUsersResponse {
  repeated string user_ids = 1;
}

message IsUserOnlineRequest {
  string user_id = 1;
}
message IsUserOnlineResponse {
  bool online = 1;
}

// ---------------------------------------------------------------------------
// AI Model Sync
// ---------------------------------------------------------------------------

message SyncModelsRequest {}
message SyncModelsResponse {
  string body_json = 1;  // Serialized SyncModelsResponse JSON
}

// ---------------------------------------------------------------------------
// Billing Alert Check
// ---------------------------------------------------------------------------

message CheckAlertsRequest {}
message CheckAlertsResponse {
  string body_json = 1;  // Serialized CheckAlertsResponse JSON
}

// ---------------------------------------------------------------------------
// AI Provider CRUD
// ---------------------------------------------------------------------------

message CreateProviderRequest {
  string body_json = 1;  // Serialized AdminCreateProvider JSON
}
message UpdateProviderRequest {
  string id = 1;
  string body_json = 2;  // Serialized AdminUpdateProvider JSON
}
message DeleteProviderRequest {
  string id = 1;
}
message ProviderResponse {
  string body_json = 1;  // Serialized response JSON
}

// ---------------------------------------------------------------------------
// AI Model CRUD
// ---------------------------------------------------------------------------

message CreateModelRequest {
  string body_json = 1;  // Serialized AdminCreateModel JSON
}
message UpdateModelRequest {
  string id = 1;
  string body_json = 2;  // Serialized AdminUpdateModel JSON
}
message DeleteModelRequest {
  string id = 1;
}
message ModelResponse {
  string body_json = 1;
}

// ---------------------------------------------------------------------------
// AI Version CRUD
// ---------------------------------------------------------------------------

message CreateVersionRequest {
  string body_json = 1;  // Serialized AdminCreateVersion JSON
}
message UpdateVersionRequest {
  string id = 1;
  string body_json = 2;  // Serialized AdminUpdateVersion JSON
}
message DeleteVersionRequest {
  string id = 1;
}
message VersionResponse {
  string body_json = 1;
}

// ---------------------------------------------------------------------------
// AI Pricing Update
// ---------------------------------------------------------------------------

message UpdatePricingRequest {
  string id = 1;
  string body_json = 2;  // Serialized AdminUpdatePricing JSON
}
message PricingResponse {
  string body_json = 1;
}

// ---------------------------------------------------------------------------
// Generic delete response
// ---------------------------------------------------------------------------

message DeleteResponse {
  bool deleted = 1;
}

// ---------------------------------------------------------------------------
// Service
// ---------------------------------------------------------------------------

service SessionAdmin {
  rpc ListWorkspaceSessions(ListWorkspaceSessionsRequest) returns (ListWorkspaceSessionsResponse);
  rpc ListUserSessions(ListUserSessionsRequest) returns (ListUserSessionsResponse);
  rpc KickUserFromWorkspace(KickUserFromWorkspaceRequest) returns (KickUserFromWorkspaceResponse);
  rpc KickUser(KickUserRequest) returns (KickUserResponse);
  rpc GetUserStatus(GetUserStatusRequest) returns (GetUserStatusResponse);
  rpc GetUserInfo(GetUserInfoRequest) returns (GetUserInfoResponse);
  rpc GetWorkspaceOnlineUsers(GetWorkspaceOnlineUsersRequest) returns (GetWorkspaceOnlineUsersResponse);
  rpc IsUserOnline(IsUserOnlineRequest) returns (IsUserOnlineResponse);
  // AI
  rpc SyncModels(SyncModelsRequest) returns (SyncModelsResponse);
  rpc CheckAlerts(CheckAlertsRequest) returns (CheckAlertsResponse);
  // AI Provider
  rpc CreateProvider(CreateProviderRequest) returns (ProviderResponse);
  rpc UpdateProvider(UpdateProviderRequest) returns (ProviderResponse);
  rpc DeleteProvider(DeleteProviderRequest) returns (DeleteResponse);
  // AI Model
  rpc CreateModel(CreateModelRequest) returns (ModelResponse);
  rpc UpdateModel(UpdateModelRequest) returns (ModelResponse);
  rpc DeleteModel(DeleteModelRequest) returns (DeleteResponse);
  // AI Version
  rpc CreateVersion(CreateVersionRequest) returns (VersionResponse);
  rpc UpdateVersion(UpdateVersionRequest) returns (VersionResponse);
  rpc DeleteVersion(DeleteVersionRequest) returns (DeleteResponse);
  // AI Pricing
  rpc UpdatePricing(UpdatePricingRequest) returns (PricingResponse);
}
