//! Curated X API tool entries: core reads, extended reads, writes, engages,
//! media, and universal admin request tools.

use crate::contract::error_code::ErrorCode;

use super::builders::{
    x_tool, ADMIN_ONLY, ALL_SIX, API_RO, WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
    WRITE_UP_AND_UTIL_WRITE, X_ENGAGE_ERR, X_READ_ERR, X_READ_USER_ERR, X_REQUEST_MUTATION_ERR,
    X_REQUEST_READ_ERR, X_WRITE_ERR,
};
use super::types::{Lane, ToolCategory, ToolEntry};

/// Curated X API tools (reads, writes, engages, media, universal request).
pub(super) fn x_api_tools() -> Vec<ToolEntry> {
    vec![
        // ── X API Core Read (all profiles including utility) ─────────
        x_tool(
            "get_tweet_by_id",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["tweet.read", "users.read"],
            true,
            false,
            ALL_SIX,
            X_READ_ERR,
        ),
        x_tool(
            "x_get_user_by_username",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["users.read"],
            true,
            false,
            ALL_SIX,
            X_READ_ERR,
        ),
        x_tool(
            "x_search_tweets",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["tweet.read", "users.read"],
            true,
            false,
            ALL_SIX,
            X_READ_ERR,
        ),
        x_tool(
            "x_get_user_mentions",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["tweet.read", "users.read"],
            true,
            false,
            ALL_SIX,
            X_READ_USER_ERR,
        ),
        x_tool(
            "x_get_user_tweets",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["tweet.read", "users.read"],
            true,
            false,
            ALL_SIX,
            X_READ_ERR,
        ),
        x_tool(
            "x_get_home_timeline",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["tweet.read", "users.read"],
            true,
            false,
            ALL_SIX,
            X_READ_USER_ERR,
        ),
        x_tool(
            "x_get_user_by_id",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["users.read"],
            true,
            false,
            ALL_SIX,
            X_READ_ERR,
        ),
        // ── X API Extended Read (workflow + api-readonly + utility-write) ──
        x_tool(
            "x_get_followers",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["follows.read", "users.read"],
            true,
            false,
            WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
            X_READ_ERR,
        ),
        x_tool(
            "x_get_following",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["follows.read", "users.read"],
            true,
            false,
            WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
            X_READ_ERR,
        ),
        x_tool(
            "x_get_liked_tweets",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["like.read", "users.read"],
            true,
            false,
            WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
            X_READ_ERR,
        ),
        x_tool(
            "x_get_bookmarks",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["bookmark.read", "users.read"],
            true,
            false,
            WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
            X_READ_USER_ERR,
        ),
        x_tool(
            "x_get_users_by_ids",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["users.read"],
            true,
            false,
            WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
            X_READ_ERR,
        ),
        x_tool(
            "x_get_tweet_liking_users",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["tweet.read", "users.read"],
            true,
            false,
            WRITE_UP_AND_API_RO_AND_UTIL_WRITE,
            X_READ_ERR,
        ),
        // ── X API Read (api-readonly only) ──────────────────────────
        x_tool(
            "x_get_me",
            ToolCategory::Read,
            Lane::Shared,
            false,
            false,
            &["users.read"],
            true,
            false,
            API_RO,
            X_READ_ERR,
        ),
        // ── X API Write (shared: workflow in write/admin, toolkit in utility) ──
        x_tool(
            "x_post_tweet",
            ToolCategory::Write,
            Lane::Shared,
            true,
            false,
            &["tweet.read", "tweet.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_WRITE_ERR,
        ),
        x_tool(
            "x_reply_to_tweet",
            ToolCategory::Write,
            Lane::Shared,
            true,
            false,
            &["tweet.read", "tweet.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_WRITE_ERR,
        ),
        x_tool(
            "x_quote_tweet",
            ToolCategory::Write,
            Lane::Shared,
            true,
            false,
            &["tweet.read", "tweet.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_WRITE_ERR,
        ),
        x_tool(
            "x_delete_tweet",
            ToolCategory::Write,
            Lane::Shared,
            true,
            false,
            &["tweet.read", "tweet.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_WRITE_ERR,
        ),
        x_tool(
            "x_post_thread",
            ToolCategory::Write,
            Lane::Shared,
            true,
            false,
            &["tweet.read", "tweet.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            &[
                ErrorCode::XNotConfigured,
                ErrorCode::XRateLimited,
                ErrorCode::XAuthExpired,
                ErrorCode::XForbidden,
                ErrorCode::XNetworkError,
                ErrorCode::XApiError,
                ErrorCode::TweetTooLong,
                ErrorCode::InvalidInput,
                ErrorCode::ThreadPartialFailure,
                ErrorCode::ScraperMutationBlocked,
                ErrorCode::PolicyDeniedBlocked,
                ErrorCode::PolicyDeniedRateLimited,
                ErrorCode::PolicyDeniedHardRule,
                ErrorCode::PolicyDeniedUserRule,
                ErrorCode::PolicyError,
            ],
        ),
        // ── X API Engage (shared: workflow in write/admin, toolkit in utility) ──
        x_tool(
            "x_like_tweet",
            ToolCategory::Engage,
            Lane::Shared,
            true,
            false,
            &["like.read", "like.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_ENGAGE_ERR,
        ),
        x_tool(
            "x_unlike_tweet",
            ToolCategory::Engage,
            Lane::Shared,
            true,
            false,
            &["like.read", "like.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_ENGAGE_ERR,
        ),
        x_tool(
            "x_follow_user",
            ToolCategory::Engage,
            Lane::Shared,
            true,
            false,
            &["follows.read", "follows.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_ENGAGE_ERR,
        ),
        x_tool(
            "x_unfollow_user",
            ToolCategory::Engage,
            Lane::Shared,
            true,
            false,
            &["follows.read", "follows.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_ENGAGE_ERR,
        ),
        x_tool(
            "x_retweet",
            ToolCategory::Engage,
            Lane::Shared,
            true,
            false,
            &["tweet.read", "tweet.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_ENGAGE_ERR,
        ),
        x_tool(
            "x_unretweet",
            ToolCategory::Engage,
            Lane::Shared,
            true,
            false,
            &["tweet.read", "tweet.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_ENGAGE_ERR,
        ),
        x_tool(
            "x_bookmark_tweet",
            ToolCategory::Engage,
            Lane::Shared,
            true,
            false,
            &["bookmark.read", "bookmark.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_ENGAGE_ERR,
        ),
        x_tool(
            "x_unbookmark_tweet",
            ToolCategory::Engage,
            Lane::Shared,
            true,
            false,
            &["bookmark.read", "bookmark.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            X_ENGAGE_ERR,
        ),
        // ── X API Media (shared: workflow in write/admin, toolkit in utility) ──
        x_tool(
            "x_upload_media",
            ToolCategory::Media,
            Lane::Shared,
            true,
            false,
            &["tweet.write", "users.read"],
            true,
            false,
            WRITE_UP_AND_UTIL_WRITE,
            &[
                ErrorCode::XNotConfigured,
                ErrorCode::UnsupportedMediaType,
                ErrorCode::FileReadError,
                ErrorCode::MediaUploadError,
                ErrorCode::XApiError,
                ErrorCode::ScraperMutationBlocked,
            ],
        ),
        // ── Universal X API Request (admin only) ────────────────────
        x_tool(
            "x_get",
            ToolCategory::Read,
            Lane::Workflow,
            false,
            false,
            &[],
            true,
            true,
            ADMIN_ONLY,
            X_REQUEST_READ_ERR,
        ),
        x_tool(
            "x_post",
            ToolCategory::Write,
            Lane::Workflow,
            true,
            true, // requires_db: policy gateway + mutation audit
            &[],
            true,
            true,
            ADMIN_ONLY,
            X_REQUEST_MUTATION_ERR,
        ),
        x_tool(
            "x_put",
            ToolCategory::Write,
            Lane::Workflow,
            true,
            true, // requires_db: policy gateway + mutation audit
            &[],
            true,
            true,
            ADMIN_ONLY,
            X_REQUEST_MUTATION_ERR,
        ),
        x_tool(
            "x_delete",
            ToolCategory::Write,
            Lane::Workflow,
            true,
            true, // requires_db: policy gateway + mutation audit
            &[],
            true,
            true,
            ADMIN_ONLY,
            X_REQUEST_MUTATION_ERR,
        ),
    ]
}
