//! Ads account and campaign endpoint definitions (8 endpoints, Admin-only, host: ads-api.x.com).

use crate::tools::manifest::ToolCategory;

use crate::spec::params::{EndpointDef, HttpMethod, ParamDef, ParamType};

use super::shared::{
    ADMIN_ONLY, PARAM_ACCOUNT_ID, PARAM_ADS_COUNT, PARAM_ADS_CURSOR, PARAM_CAMPAIGN_ID,
    PARAM_WITH_DELETED, X_READ_ERR, X_WRITE_ERR,
};

pub(super) static ADS_ACCOUNT_ENDPOINTS: &[EndpointDef] = &[
    // ── Ads Accounts (3) ──────────────────────────────────────────
    EndpointDef {
        tool_name: "x_ads_accounts",
        description: "List all advertising accounts the authenticating user has access to",
        method: HttpMethod::Get,
        path: "/12/accounts",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read"],
        params: &[PARAM_WITH_DELETED, PARAM_ADS_CURSOR, PARAM_ADS_COUNT],
        error_codes: X_READ_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    EndpointDef {
        tool_name: "x_ads_account_by_id",
        description: "Get details of a specific advertising account",
        method: HttpMethod::Get,
        path: "/12/accounts/{account_id}",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read"],
        params: &[PARAM_ACCOUNT_ID, PARAM_WITH_DELETED],
        error_codes: X_READ_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    EndpointDef {
        tool_name: "x_ads_analytics",
        description: "Retrieve analytics and performance metrics for an ads account",
        method: HttpMethod::Get,
        path: "/12/stats/accounts/{account_id}",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read"],
        params: &[
            PARAM_ACCOUNT_ID,
            ParamDef {
                name: "entity",
                param_type: ParamType::String,
                required: false,
                description: "Entity type: CAMPAIGN, LINE_ITEM, PROMOTED_TWEET",
                default: None,
            },
            ParamDef {
                name: "entity_ids",
                param_type: ParamType::StringArray,
                required: false,
                description: "Comma-separated entity IDs to retrieve metrics for",
                default: None,
            },
            ParamDef {
                name: "start_time",
                param_type: ParamType::String,
                required: false,
                description: "Start time in ISO 8601 format",
                default: None,
            },
            ParamDef {
                name: "end_time",
                param_type: ParamType::String,
                required: false,
                description: "End time in ISO 8601 format",
                default: None,
            },
            ParamDef {
                name: "granularity",
                param_type: ParamType::String,
                required: false,
                description: "Aggregation granularity: HOUR, DAY, TOTAL",
                default: Some("DAY"),
            },
            ParamDef {
                name: "metric_groups",
                param_type: ParamType::StringArray,
                required: false,
                description: "Comma-separated metric groups (e.g. ENGAGEMENT,BILLING)",
                default: None,
            },
        ],
        error_codes: X_READ_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    // ── Campaigns (5) ─────────────────────────────────────────────
    EndpointDef {
        tool_name: "x_ads_campaign_by_id",
        description: "Get details of a specific campaign",
        method: HttpMethod::Get,
        path: "/12/accounts/{account_id}/campaigns/{campaign_id}",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read"],
        params: &[PARAM_ACCOUNT_ID, PARAM_CAMPAIGN_ID, PARAM_WITH_DELETED],
        error_codes: X_READ_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    EndpointDef {
        tool_name: "x_ads_campaign_create",
        description: "Create a new advertising campaign",
        method: HttpMethod::Post,
        path: "/12/accounts/{account_id}/campaigns",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read", "ads.write"],
        params: &[
            PARAM_ACCOUNT_ID,
            ParamDef {
                name: "name",
                param_type: ParamType::String,
                required: true,
                description: "Campaign name",
                default: None,
            },
            ParamDef {
                name: "funding_instrument_id",
                param_type: ParamType::String,
                required: true,
                description: "Funding instrument ID for the campaign budget",
                default: None,
            },
            ParamDef {
                name: "status",
                param_type: ParamType::String,
                required: false,
                description: "Campaign status: ACTIVE, PAUSED, DRAFT",
                default: Some("PAUSED"),
            },
            ParamDef {
                name: "daily_budget_amount_local_micro",
                param_type: ParamType::Integer,
                required: false,
                description: "Daily budget in microcurrency units (e.g. 5000000 = $5.00)",
                default: None,
            },
            ParamDef {
                name: "start_time",
                param_type: ParamType::String,
                required: false,
                description: "Campaign start time in ISO 8601 format",
                default: None,
            },
            ParamDef {
                name: "end_time",
                param_type: ParamType::String,
                required: false,
                description: "Campaign end time in ISO 8601 format",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    EndpointDef {
        tool_name: "x_ads_campaign_delete",
        description: "Delete (archive) a campaign",
        method: HttpMethod::Delete,
        path: "/12/accounts/{account_id}/campaigns/{campaign_id}",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read", "ads.write"],
        params: &[PARAM_ACCOUNT_ID, PARAM_CAMPAIGN_ID],
        error_codes: X_WRITE_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    EndpointDef {
        tool_name: "x_ads_campaign_update",
        description: "Update an existing campaign's name, status, or budget",
        method: HttpMethod::Put,
        path: "/12/accounts/{account_id}/campaigns/{campaign_id}",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read", "ads.write"],
        params: &[
            PARAM_ACCOUNT_ID,
            PARAM_CAMPAIGN_ID,
            ParamDef {
                name: "name",
                param_type: ParamType::String,
                required: false,
                description: "Updated campaign name",
                default: None,
            },
            ParamDef {
                name: "status",
                param_type: ParamType::String,
                required: false,
                description: "Updated status: ACTIVE, PAUSED",
                default: None,
            },
            ParamDef {
                name: "daily_budget_amount_local_micro",
                param_type: ParamType::Integer,
                required: false,
                description: "Updated daily budget in microcurrency units",
                default: None,
            },
            ParamDef {
                name: "start_time",
                param_type: ParamType::String,
                required: false,
                description: "Updated start time in ISO 8601 format",
                default: None,
            },
            ParamDef {
                name: "end_time",
                param_type: ParamType::String,
                required: false,
                description: "Updated end time in ISO 8601 format",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    EndpointDef {
        tool_name: "x_ads_campaigns",
        description: "List campaigns for an advertising account",
        method: HttpMethod::Get,
        path: "/12/accounts/{account_id}/campaigns",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read"],
        params: &[
            PARAM_ACCOUNT_ID,
            ParamDef {
                name: "campaign_ids",
                param_type: ParamType::StringArray,
                required: false,
                description: "Comma-separated campaign IDs to filter by",
                default: None,
            },
            PARAM_WITH_DELETED,
            PARAM_ADS_CURSOR,
            PARAM_ADS_COUNT,
        ],
        error_codes: X_READ_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
];
