//! Ads line items, promoted tweets, and targeting endpoint definitions (8 endpoints).

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_ID,
    PARAM_WITH_DELETED, X_READ_ERR, X_WRITE_ERR,
};

pub(super) static ADS_LINE_ITEM_ENDPOINTS: &[EndpointDef] = &[
    // ── Funding Instruments (1) ────────────────────────────────────
    EndpointDef {
        tool_name: "x_ads_funding_instruments",
        description: "List funding instruments (payment methods) for an ads account",
        method: HttpMethod::Get,
        path: "/12/accounts/{account_id}/funding_instruments",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read"],
        params: &[
            PARAM_ACCOUNT_ID,
            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"),
    },
    // ── Line Items (2) ─────────────────────────────────────────────
    EndpointDef {
        tool_name: "x_ads_line_item_create",
        description: "Create a new line item (ad group) within a campaign",
        method: HttpMethod::Post,
        path: "/12/accounts/{account_id}/line_items",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read", "ads.write"],
        params: &[
            PARAM_ACCOUNT_ID,
            PARAM_CAMPAIGN_ID,
            ParamDef {
                name: "bid_amount_local_micro",
                param_type: ParamType::Integer,
                required: true,
                description: "Bid amount in microcurrency units",
                default: None,
            },
            ParamDef {
                name: "product_type",
                param_type: ParamType::String,
                required: true,
                description: "Product type: PROMOTED_TWEETS, PROMOTED_ACCOUNT",
                default: None,
            },
            ParamDef {
                name: "placements",
                param_type: ParamType::StringArray,
                required: true,
                description: "Comma-separated placements: ALL_ON_TWITTER, PUBLISHER_NETWORK",
                default: None,
            },
            ParamDef {
                name: "objective",
                param_type: ParamType::String,
                required: true,
                description: "Campaign objective: AWARENESS, ENGAGEMENTS, VIDEO_VIEWS, etc.",
                default: None,
            },
            ParamDef {
                name: "bid_type",
                param_type: ParamType::String,
                required: false,
                description: "Bid type: AUTO, MAX, TARGET",
                default: None,
            },
            ParamDef {
                name: "total_budget_amount_local_micro",
                param_type: ParamType::Integer,
                required: false,
                description: "Total line item budget in microcurrency units",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    EndpointDef {
        tool_name: "x_ads_line_items",
        description: "List line items (ad groups) for an advertising account",
        method: HttpMethod::Get,
        path: "/12/accounts/{account_id}/line_items",
        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,
            },
            ParamDef {
                name: "line_item_ids",
                param_type: ParamType::StringArray,
                required: false,
                description: "Comma-separated line item 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"),
    },
    // ── Promoted Tweets (2) ────────────────────────────────────────
    EndpointDef {
        tool_name: "x_ads_promoted_tweet_create",
        description: "Promote a tweet under a line item",
        method: HttpMethod::Post,
        path: "/12/accounts/{account_id}/promoted_tweets",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read", "ads.write"],
        params: &[
            PARAM_ACCOUNT_ID,
            ParamDef {
                name: "line_item_id",
                param_type: ParamType::String,
                required: true,
                description: "Line item ID to associate the promoted tweet with",
                default: None,
            },
            ParamDef {
                name: "tweet_ids",
                param_type: ParamType::StringArray,
                required: true,
                description: "Comma-separated tweet IDs to promote",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    EndpointDef {
        tool_name: "x_ads_promoted_tweets",
        description: "List promoted tweets for an advertising account",
        method: HttpMethod::Get,
        path: "/12/accounts/{account_id}/promoted_tweets",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read"],
        params: &[
            PARAM_ACCOUNT_ID,
            ParamDef {
                name: "line_item_ids",
                param_type: ParamType::StringArray,
                required: false,
                description: "Comma-separated line item 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"),
    },
    // ── Targeting Criteria (3) ─────────────────────────────────────
    EndpointDef {
        tool_name: "x_ads_targeting_create",
        description: "Create targeting criteria for a line item",
        method: HttpMethod::Post,
        path: "/12/accounts/{account_id}/targeting_criteria",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read", "ads.write"],
        params: &[
            PARAM_ACCOUNT_ID,
            ParamDef {
                name: "line_item_id",
                param_type: ParamType::String,
                required: true,
                description: "Line item ID to apply targeting to",
                default: None,
            },
            ParamDef {
                name: "targeting_type",
                param_type: ParamType::String,
                required: true,
                description: "Targeting type: LOCATION, KEYWORD, INTEREST, etc.",
                default: None,
            },
            ParamDef {
                name: "targeting_value",
                param_type: ParamType::String,
                required: true,
                description: "Targeting value (depends on targeting_type)",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
    EndpointDef {
        tool_name: "x_ads_targeting_criteria",
        description: "List targeting criteria for an advertising account",
        method: HttpMethod::Get,
        path: "/12/accounts/{account_id}/targeting_criteria",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read"],
        params: &[
            PARAM_ACCOUNT_ID,
            ParamDef {
                name: "line_item_ids",
                param_type: ParamType::StringArray,
                required: false,
                description: "Comma-separated line item 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"),
    },
    EndpointDef {
        tool_name: "x_ads_targeting_delete",
        description: "Delete targeting criteria from a line item",
        method: HttpMethod::Delete,
        path: "/12/accounts/{account_id}/targeting_criteria/{id}",
        category: ToolCategory::Ads,
        profiles: ADMIN_ONLY,
        scopes: &["ads.read", "ads.write"],
        params: &[PARAM_ACCOUNT_ID, PARAM_ID],
        error_codes: X_WRITE_ERR,
        api_version: "ads-v12",
        group: "ads",
        host: Some("ads-api.x.com"),
    },
];
