//! Batch Lookups, Tweet Metadata, and Pin Management endpoint definitions.

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

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

use super::shared::{
    ALL_SIX, PARAM_EXPANSIONS, PARAM_ID, PARAM_MAX_RESULTS, PARAM_PAGINATION_TOKEN,
    PARAM_TWEET_FIELDS, PARAM_USER_FIELDS, PARAM_USER_ID, WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
    WRITE_UP_AND_UTIL_WRITE, X_READ_ERR, X_WRITE_ERR,
};

pub(super) static TWEET_ENDPOINTS: &[EndpointDef] = &[
    // ── Batch Lookups (3) ──────────────────────────────────────────
    EndpointDef {
        tool_name: "x_v2_tweets_lookup",
        description: "Look up multiple tweets by their IDs in a single request",
        method: HttpMethod::Get,
        path: "/2/tweets",
        category: ToolCategory::Read,
        profiles: ALL_SIX,
        scopes: &["tweet.read", "users.read"],
        params: &[
            ParamDef {
                name: "ids",
                param_type: ParamType::StringArray,
                required: true,
                description: "Comma-separated tweet IDs (up to 100)",
                default: None,
            },
            PARAM_TWEET_FIELDS,
            PARAM_USER_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "tweets",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_users_lookup_by_usernames",
        description: "Look up multiple users by their usernames in a single request",
        method: HttpMethod::Get,
        path: "/2/users/by",
        category: ToolCategory::Read,
        profiles: ALL_SIX,
        scopes: &["users.read"],
        params: &[
            ParamDef {
                name: "usernames",
                param_type: ParamType::StringArray,
                required: true,
                description: "Comma-separated usernames (up to 100, without @ prefix)",
                default: None,
            },
            PARAM_USER_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "users",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_tweets_retweeted_by",
        description: "Get users who retweeted a specific tweet",
        method: HttpMethod::Get,
        path: "/2/tweets/{id}/retweeted_by",
        category: ToolCategory::Read,
        profiles: ALL_SIX,
        scopes: &["tweet.read", "users.read"],
        params: &[
            PARAM_ID,
            PARAM_MAX_RESULTS,
            PARAM_PAGINATION_TOKEN,
            PARAM_USER_FIELDS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "tweets",
        host: None,
    },
    // ── Tweet Metadata (4) ─────────────────────────────────────────
    EndpointDef {
        tool_name: "x_v2_tweets_quote_tweets",
        description: "Get tweets that quote a specific tweet",
        method: HttpMethod::Get,
        path: "/2/tweets/{id}/quote_tweets",
        category: ToolCategory::Read,
        profiles: ALL_SIX,
        scopes: &["tweet.read", "users.read"],
        params: &[
            PARAM_ID,
            PARAM_MAX_RESULTS,
            PARAM_PAGINATION_TOKEN,
            PARAM_TWEET_FIELDS,
            PARAM_USER_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "tweets",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_tweets_counts_recent",
        description: "Get count of tweets matching a query from the last 7 days",
        method: HttpMethod::Get,
        path: "/2/tweets/counts/recent",
        category: ToolCategory::Read,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["tweet.read"],
        params: &[
            ParamDef {
                name: "query",
                param_type: ParamType::String,
                required: true,
                description: "Search query (same syntax as search/recent)",
                default: None,
            },
            ParamDef {
                name: "granularity",
                param_type: ParamType::String,
                required: false,
                description: "Aggregation granularity: minute, hour, or day",
                default: Some("hour"),
            },
            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,
            },
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "tweets",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_tweets_hide_reply",
        description: "Hide a reply to one of your tweets",
        method: HttpMethod::Put,
        path: "/2/tweets/{id}/hidden",
        category: ToolCategory::Moderation,
        profiles: WRITE_UP_AND_UTIL_WRITE,
        scopes: &["tweet.read", "tweet.moderate.write"],
        params: &[
            PARAM_ID,
            ParamDef {
                name: "hidden",
                param_type: ParamType::Boolean,
                required: true,
                description: "Set to true to hide, false to unhide",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "v2",
        group: "tweets",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_tweets_unhide_reply",
        description: "Unhide a previously hidden reply",
        method: HttpMethod::Put,
        path: "/2/tweets/{id}/hidden",
        category: ToolCategory::Moderation,
        profiles: WRITE_UP_AND_UTIL_WRITE,
        scopes: &["tweet.read", "tweet.moderate.write"],
        params: &[
            PARAM_ID,
            ParamDef {
                name: "hidden",
                param_type: ParamType::Boolean,
                required: true,
                description: "Set to false to unhide",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "v2",
        group: "tweets",
        host: None,
    },
    // ── Pin Management (2) ─────────────────────────────────────────
    EndpointDef {
        tool_name: "x_v2_users_pin_tweet",
        description: "Pin a tweet to your profile",
        method: HttpMethod::Put,
        path: "/2/users/{user_id}/pinned_tweet",
        category: ToolCategory::Engage,
        profiles: WRITE_UP_AND_UTIL_WRITE,
        scopes: &["tweet.read", "users.read", "tweet.write"],
        params: &[
            PARAM_USER_ID,
            ParamDef {
                name: "tweet_id",
                param_type: ParamType::String,
                required: true,
                description: "ID of the tweet to pin",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "v2",
        group: "users",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_users_unpin_tweet",
        description: "Unpin a tweet from your profile",
        method: HttpMethod::Delete,
        path: "/2/users/{user_id}/pinned_tweet",
        category: ToolCategory::Engage,
        profiles: WRITE_UP_AND_UTIL_WRITE,
        scopes: &["tweet.read", "users.read", "tweet.write"],
        params: &[PARAM_USER_ID],
        error_codes: X_WRITE_ERR,
        api_version: "v2",
        group: "users",
        host: None,
    },
];
