use serde::Serialize;

/// Configuration for generating discovery content. Allows consuming applications
/// to mount cedros-sunscreen at different base paths and compose unified discovery.
#[derive(Debug, Clone)]
pub struct ContentConfig {
    pub base_path: String,
    pub name: String,
    pub version: String,
    pub description: String,
}

impl ContentConfig {
    pub fn new(base_path: &str) -> Self {
        Self {
            base_path: base_path.to_string(),
            name: "cedros-sunscreen".to_string(),
            version: env!("CARGO_PKG_VERSION").to_string(),
            description: "Sanctions screening API for blockchain addresses".to_string(),
        }
    }

    pub fn path(&self, endpoint: &str) -> String {
        format!("{}{}", self.base_path, endpoint)
    }
}

/// Canonical discovery index (/.well-known/ai-discovery.json).
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AiDiscoveryIndex {
    pub version: String,
    pub name: String,
    pub description: String,
    pub endpoints: DiscoveryEndpoints,
    pub skills: Vec<SkillReference>,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DiscoveryEndpoints {
    pub llms_txt: String,
    pub llms_full_txt: String,
    pub llms_admin_txt: String,
    pub skill_index_markdown: String,
    pub skill_index_json: String,
    pub agent_guide: String,
    pub openapi: String,
    pub a2a_agent_card: String,
    pub ai_plugin: String,
    pub mcp: String,
    pub health: String,
    pub skills_bundle: String,
}

#[derive(Debug, Clone, Serialize)]
pub struct SkillReference {
    pub id: String,
    pub name: String,
    pub path: String,
    pub description: String,
    pub requires_auth: bool,
}

/// OpenAI plugin manifest (/.well-known/ai-plugin.json).
#[derive(Debug, Serialize)]
pub struct AiPluginManifest {
    pub schema_version: String,
    pub name_for_human: String,
    pub name_for_model: String,
    pub description_for_human: String,
    pub description_for_model: String,
    pub auth: AiPluginAuth,
    pub api: AiPluginApi,
}

#[derive(Debug, Serialize)]
pub struct AiPluginAuth {
    #[serde(rename = "type")]
    pub auth_type: String,
}

#[derive(Debug, Serialize)]
pub struct AiPluginApi {
    #[serde(rename = "type")]
    pub api_type: String,
    pub url: String,
}

/// A2A agent card (/.well-known/agent.json).
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AgentCard {
    pub name: String,
    pub description: String,
    pub url: String,
    pub version: String,
    pub capabilities: AgentCapabilities,
    pub skills: Vec<AgentSkill>,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AgentCapabilities {
    pub sanctions_screening: bool,
    pub country_screening: bool,
    pub bulk_list_download: bool,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AgentSkill {
    pub id: String,
    pub name: String,
    pub description: String,
    pub documentation_url: String,
}

/// MCP discovery (/.well-known/mcp).
#[derive(Debug, Serialize)]
pub struct McpDiscovery {
    pub name: String,
    pub version: String,
    pub description: String,
    pub tools: Vec<McpTool>,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct McpTool {
    pub name: String,
    pub description: String,
    pub input_schema: serde_json::Value,
}

/// Heartbeat response (/heartbeat.json).
#[derive(Debug, Serialize)]
pub struct HeartbeatResponse {
    pub status: String,
    pub name: String,
    pub version: String,
    pub capabilities: Vec<String>,
    pub endpoints: Vec<String>,
}

/// Skill metadata (/skill.json).
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SkillMetadata {
    pub name: String,
    pub version: String,
    pub description: String,
    pub category: String,
    pub api_base: String,
    pub capabilities: SkillCapabilities,
    pub authentication: SkillAuth,
    pub skills: Vec<SkillReference>,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SkillCapabilities {
    pub sanctions_list: bool,
    pub address_check: bool,
    pub country_codes: bool,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SkillAuth {
    pub methods: Vec<String>,
    pub header: String,
    pub note: String,
}
