syntax = "proto3";

package proto;

option csharp_namespace = "DysonNetwork.Shared.Proto";

import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "account.proto";
import "file.proto";

message CustomAppOauthConfig {
  string client_uri = 1;
  repeated string redirect_uris = 2;
  repeated string post_logout_redirect_uris = 3;
  repeated string allowed_scopes = 4;
  repeated string allowed_grant_types = 5;
  bool require_pkce = 6;
  bool allow_offline_access = 7;
}

message CustomAppLinks {
  string home_page = 1;
  string privacy_policy = 2;
  string terms_of_service = 3;
}

enum CustomAppStatus {
  CUSTOM_APP_STATUS_UNSPECIFIED = 0;
  DEVELOPING = 1;
  STAGING = 2;
  PRODUCTION = 3;
  SUSPENDED = 4;
}

message CustomApp {
  string id = 1;
  string slug = 2;
  string name = 3;
  string description = 4;
  CustomAppStatus status = 5;

  // jsonb columns represented as bytes
  CloudFile picture = 6;
  CloudFile background = 7;
  VerificationMark verification = 8;
  CustomAppLinks links = 9;
  CustomAppOauthConfig oauth_config = 13;

  string project_id = 10;

  google.protobuf.Timestamp created_at = 11;
  google.protobuf.Timestamp updated_at = 12;
}

message CustomAppSecret {
  string id = 1;
  string secret = 2;
  string description = 3;
  google.protobuf.Timestamp expired_at = 4;
  bool is_oidc = 5;

  string app_id = 6;

  google.protobuf.Timestamp created_at = 7;
  google.protobuf.Timestamp updated_at = 8;
}

message GetCustomAppRequest {
  oneof Query {
    string id = 1;
    string slug = 2;
  }
}

message GetCustomAppResponse {
  CustomApp app = 1;
}

message CheckCustomAppSecretRequest {
  oneof SecretIdentifier {
    string secret_id = 1;
    string app_id = 2;
  }
  string secret = 3;
  optional bool is_oidc = 4;
}

message CheckCustomAppSecretResponse {
  bool valid = 1;
}

service CustomAppService {
  rpc GetCustomApp(GetCustomAppRequest) returns (GetCustomAppResponse);
  rpc CheckCustomAppSecret(CheckCustomAppSecretRequest) returns (CheckCustomAppSecretResponse);
}

// BotAccount represents a bot account in the system
// It extends the base Account with bot-specific fields
message BotAccount {
  // Base account information
  Account account = 1;

  // Bot-specific information
  string slug = 2;         // Unique identifier for the bot
  bool is_active = 3;     // Whether the bot is currently active
  string automated_id = 5; // The bot ID

  // Timestamps
  google.protobuf.Timestamp created_at = 6;
  google.protobuf.Timestamp updated_at = 7;
}

// Request/Response messages for BotAccount operations
message CreateBotAccountRequest {
  Account account = 1;
  string automated_id = 2;
  google.protobuf.StringValue picture_id = 8;
  google.protobuf.StringValue background_id = 9;
}

message CreateBotAccountResponse {
  BotAccount bot = 1;    // The created bot account
}

message UpdateBotAccountRequest {
  string automated_id = 1;       // ID of the bot account to update
  Account account = 2;           // Updated account information
  optional string picture_id = 8;
  optional string background_id = 9;
}

message UpdateBotAccountResponse {
  BotAccount bot = 1;    // The updated bot account
}

message DeleteBotAccountRequest {
  string automated_id = 1;       // ID of the bot account to delete
  bool force = 2;                // Whether to force delete (bypass soft delete)
}

message DeleteBotAccountResponse {
  bool success = 1;              // Whether the deletion was successful
}

message ApiKey {
  string id = 1;
  string label = 2;
  string account_id = 3;
  string session_id = 4;
  google.protobuf.StringValue key = 5;
  google.protobuf.Timestamp created_at = 6;
  google.protobuf.Timestamp updated_at = 7;
}

message GetApiKeyRequest {
  string id = 1;
}

message ListApiKeyRequest {
  string automated_id = 1;
}

message GetApiKeyBatchResponse {
  repeated ApiKey data = 1;
}

message DeleteApiKeyResponse {
  bool success = 1;
}

// This service should be implemented by the Pass service to handle the creation, update, and deletion of bot accounts
service BotAccountReceiverService {
  rpc CreateBotAccount(CreateBotAccountRequest) returns (CreateBotAccountResponse);
  rpc UpdateBotAccount(UpdateBotAccountRequest) returns (UpdateBotAccountResponse);
  rpc DeleteBotAccount(DeleteBotAccountRequest) returns (DeleteBotAccountResponse);

  rpc GetApiKey(GetApiKeyRequest) returns (ApiKey);
  rpc ListApiKey(ListApiKeyRequest) returns (GetApiKeyBatchResponse);
  rpc CreateApiKey(ApiKey) returns (ApiKey);
  rpc UpdateApiKey(ApiKey) returns (ApiKey);
  rpc RotateApiKey(GetApiKeyRequest) returns (ApiKey);
  rpc DeleteApiKey(GetApiKeyRequest) returns (DeleteApiKeyResponse);
}
  
