use service_kit::api_dto;

#[api_dto]
#[derive(PartialEq)]
pub enum ServiceStatus {
    Active,
    Degraded,
    Maintenance,
}

#[api_dto]
#[derive(PartialEq)]
pub enum ServiceRole {
    DataProvider,
    ReportGenerator,
    Persistence,
    Gateway,
    Other,
}

/// 字段类型枚举
#[api_dto]
#[derive(PartialEq)]
pub enum FieldType {
    Text,
    Password,
    Url,
    Boolean,
    Select,
}

/// 配置键枚举 - 强类型定义所有可能的配置项
#[api_dto]
#[derive(PartialEq, Eq, Hash)]
pub enum ConfigKey {
    /// API 密钥 / Token
    ApiKey,
    /// API Token (Tushare 等使用)
    ApiToken,
    /// API 基础 URL
    ApiUrl,
    /// 基础 URL (通用)
    BaseUrl,
    /// 密钥 (Secret)
    SecretKey,
    /// 用户名
    Username,
    /// 密码
    Password,
    /// 沙箱模式开关
    SandboxMode,
    /// 区域 / Region
    Region,
}

/// 单个配置字段的定义
#[api_dto]
#[derive(PartialEq)]
pub struct ConfigFieldSchema {
    pub key: ConfigKey,
    pub label: String,
    pub field_type: FieldType,
    pub required: bool,
    pub placeholder: Option<String>,
    pub default_value: Option<String>,
    pub description: Option<String>,
    /// Options for 'Select' type
    pub options: Option<Vec<String>>,
}

/// 服务元数据
#[api_dto]
#[derive(PartialEq)]
pub struct ProviderMetadata {
    pub id: String,
    pub name_en: String,
    pub name_cn: String,
    pub description: String,
    pub icon_url: Option<String>,
    
    /// 该服务需要的配置字段列表
    pub config_schema: Vec<ConfigFieldSchema>,
    
    /// 是否支持“测试连接”功能
    pub supports_test_connection: bool,
}

#[api_dto]
pub struct ServiceRegistration {
    /// Unique ID for this service instance (e.g., "tushare-provider-uuid")
    pub service_id: String,
    /// Service type/name (e.g., "tushare")
    pub service_name: String,
    /// The role/category of the service
    pub role: ServiceRole,
    /// Base URL for the service (e.g., "http://10.0.1.5:8000")
    pub base_url: String,
    /// Health check endpoint
    pub health_check_url: String,
    /// Optional provider metadata (only for DataProvider role)
    pub metadata: Option<ProviderMetadata>,
}

#[api_dto]
pub struct Heartbeat {
    pub service_id: String,
    pub status: ServiceStatus,
}
