//! Spaces and Direct Messages endpoint definitions (14 endpoints).

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

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

use super::shared::{
    PARAM_DM_EVENT_FIELDS, PARAM_EXPANSIONS, PARAM_ID, PARAM_MAX_RESULTS, PARAM_PAGINATION_TOKEN,
    PARAM_PARTICIPANT_ID, PARAM_SPACE_FIELDS, PARAM_TWEET_FIELDS, PARAM_USER_FIELDS,
    WRITE_UP_AND_API_RO_AND_UTIL_WRITE, WRITE_UP_AND_UTIL_WRITE, X_READ_ERR, X_WRITE_ERR,
};

pub(super) static SPACE_ENDPOINTS: &[EndpointDef] = &[
    // ── Spaces (6) ─────────────────────────────────────────────────
    EndpointDef {
        tool_name: "x_v2_spaces_get",
        description: "Look up a Space by its ID",
        method: HttpMethod::Get,
        path: "/2/spaces/{id}",
        category: ToolCategory::Read,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["space.read"],
        params: &[PARAM_ID, PARAM_SPACE_FIELDS, PARAM_EXPANSIONS],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "spaces",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_spaces_lookup",
        description: "Look up multiple Spaces by their IDs",
        method: HttpMethod::Get,
        path: "/2/spaces",
        category: ToolCategory::Read,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["space.read"],
        params: &[
            ParamDef {
                name: "ids",
                param_type: ParamType::StringArray,
                required: true,
                description: "Comma-separated Space IDs",
                default: None,
            },
            PARAM_SPACE_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "spaces",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_spaces_by_creator",
        description: "Get Spaces created by specific users",
        method: HttpMethod::Get,
        path: "/2/spaces/by/creator_ids",
        category: ToolCategory::Read,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["space.read", "users.read"],
        params: &[
            ParamDef {
                name: "user_ids",
                param_type: ParamType::StringArray,
                required: true,
                description: "Comma-separated user IDs of Space creators",
                default: None,
            },
            PARAM_SPACE_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "spaces",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_spaces_search",
        description: "Search for Spaces by title",
        method: HttpMethod::Get,
        path: "/2/spaces/search",
        category: ToolCategory::Read,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["space.read"],
        params: &[
            ParamDef {
                name: "query",
                param_type: ParamType::String,
                required: true,
                description: "Search query to find Spaces by title",
                default: None,
            },
            ParamDef {
                name: "state",
                param_type: ParamType::String,
                required: false,
                description: "Filter by state: live, scheduled, or all",
                default: Some("all"),
            },
            PARAM_SPACE_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "spaces",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_spaces_buyers",
        description: "Get users who purchased a ticket to a Space",
        method: HttpMethod::Get,
        path: "/2/spaces/{id}/buyers",
        category: ToolCategory::Read,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["space.read", "users.read"],
        params: &[PARAM_ID, PARAM_USER_FIELDS],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "spaces",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_spaces_tweets",
        description: "Get tweets shared in a Space",
        method: HttpMethod::Get,
        path: "/2/spaces/{id}/tweets",
        category: ToolCategory::Read,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["space.read", "tweet.read", "users.read"],
        params: &[
            PARAM_ID,
            PARAM_TWEET_FIELDS,
            PARAM_USER_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "spaces",
        host: None,
    },
    // ── Direct Messages (8) ───────────────────────────────────────
    EndpointDef {
        tool_name: "x_v2_dm_conversations",
        description: "List DM conversations for the authenticated user",
        method: HttpMethod::Get,
        path: "/2/dm_conversations",
        category: ToolCategory::DirectMessage,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["dm.read", "users.read"],
        params: &[
            PARAM_MAX_RESULTS,
            PARAM_PAGINATION_TOKEN,
            PARAM_DM_EVENT_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "direct_messages",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_dm_conversation_by_id",
        description: "Look up a DM conversation by its ID",
        method: HttpMethod::Get,
        path: "/2/dm_conversations/{id}",
        category: ToolCategory::DirectMessage,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["dm.read", "users.read"],
        params: &[PARAM_ID, PARAM_DM_EVENT_FIELDS, PARAM_EXPANSIONS],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "direct_messages",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_dm_events_by_conversation",
        description: "Get DM events (messages) in a specific conversation",
        method: HttpMethod::Get,
        path: "/2/dm_conversations/{id}/dm_events",
        category: ToolCategory::DirectMessage,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["dm.read", "users.read"],
        params: &[
            PARAM_ID,
            PARAM_MAX_RESULTS,
            PARAM_PAGINATION_TOKEN,
            PARAM_DM_EVENT_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "direct_messages",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_dm_events_by_participant",
        description: "Get DM events with a specific participant",
        method: HttpMethod::Get,
        path: "/2/dm_conversations/with/{participant_id}/dm_events",
        category: ToolCategory::DirectMessage,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["dm.read", "users.read"],
        params: &[
            PARAM_PARTICIPANT_ID,
            PARAM_MAX_RESULTS,
            PARAM_PAGINATION_TOKEN,
            PARAM_DM_EVENT_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "direct_messages",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_dm_events",
        description: "List all recent DM events across conversations",
        method: HttpMethod::Get,
        path: "/2/dm_events",
        category: ToolCategory::DirectMessage,
        profiles: WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
        scopes: &["dm.read", "users.read"],
        params: &[
            PARAM_MAX_RESULTS,
            PARAM_PAGINATION_TOKEN,
            PARAM_DM_EVENT_FIELDS,
            PARAM_EXPANSIONS,
        ],
        error_codes: X_READ_ERR,
        api_version: "v2",
        group: "direct_messages",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_dm_send_in_conversation",
        description: "Send a DM message in an existing conversation",
        method: HttpMethod::Post,
        path: "/2/dm_conversations/{id}/messages",
        category: ToolCategory::DirectMessage,
        profiles: WRITE_UP_AND_UTIL_WRITE,
        scopes: &["dm.write", "dm.read", "users.read"],
        params: &[
            PARAM_ID,
            ParamDef {
                name: "text",
                param_type: ParamType::String,
                required: true,
                description: "The message text to send",
                default: None,
            },
            ParamDef {
                name: "attachments",
                param_type: ParamType::StringArray,
                required: false,
                description: "Comma-separated media IDs to attach",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "v2",
        group: "direct_messages",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_dm_send_to_participant",
        description: "Send a DM message to a specific user (creates 1-on-1 conversation)",
        method: HttpMethod::Post,
        path: "/2/dm_conversations/with/{participant_id}/messages",
        category: ToolCategory::DirectMessage,
        profiles: WRITE_UP_AND_UTIL_WRITE,
        scopes: &["dm.write", "dm.read", "users.read"],
        params: &[
            PARAM_PARTICIPANT_ID,
            ParamDef {
                name: "text",
                param_type: ParamType::String,
                required: true,
                description: "The message text to send",
                default: None,
            },
            ParamDef {
                name: "attachments",
                param_type: ParamType::StringArray,
                required: false,
                description: "Comma-separated media IDs to attach",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "v2",
        group: "direct_messages",
        host: None,
    },
    EndpointDef {
        tool_name: "x_v2_dm_create_group",
        description: "Create a new group DM conversation with an initial message",
        method: HttpMethod::Post,
        path: "/2/dm_conversations",
        category: ToolCategory::DirectMessage,
        profiles: WRITE_UP_AND_UTIL_WRITE,
        scopes: &["dm.write", "dm.read", "users.read"],
        params: &[
            ParamDef {
                name: "participant_ids",
                param_type: ParamType::StringArray,
                required: true,
                description: "Comma-separated user IDs of group participants",
                default: None,
            },
            ParamDef {
                name: "text",
                param_type: ParamType::String,
                required: true,
                description: "The initial message text for the group conversation",
                default: None,
            },
            ParamDef {
                name: "attachments",
                param_type: ParamType::StringArray,
                required: false,
                description: "Comma-separated media IDs to attach",
                default: None,
            },
        ],
        error_codes: X_WRITE_ERR,
        api_version: "v2",
        group: "direct_messages",
        host: None,
    },
];
