use serde::Deserialize;

// =============================================================================
// Shared nested types
// =============================================================================

/// Minimal team reference used inside player/transaction responses.
#[derive(Debug, Deserialize)]
pub struct TeamRef {
    pub id: i64,
}

/// Minimal player reference used inside transaction responses.
#[derive(Debug, Deserialize)]
pub struct PlayerRef {
    pub id: i64,
}

/// Manager sub-object nested inside TeamData.
#[derive(Debug, Deserialize)]
pub struct Manager {
    pub name: Option<String>,
}

/// Division sub-object nested inside TeamData.
#[derive(Debug, Deserialize)]
pub struct Division {
    pub id: Option<i64>,
    pub division_name: Option<String>,
    pub league_abbrev: Option<String>,
}

// =============================================================================
// Teams
// =============================================================================

#[derive(Debug, Deserialize)]
pub struct TeamsResponse {
    pub count: u32,
    pub teams: Vec<TeamData>,
}

#[derive(Debug, Deserialize)]
pub struct TeamData {
    pub id: i64,
    #[serde(default)]
    pub abbrev: Option<String>,
    #[serde(rename = "sname", default)]
    pub short_name: Option<String>,
    #[serde(rename = "lname", default)]
    pub long_name: Option<String>,
    #[serde(default)]
    pub thumbnail: Option<String>,
    #[serde(default)]
    pub color: Option<String>,
    #[serde(default)]
    pub dice_color: Option<String>,
    #[serde(default)]
    pub stadium: Option<String>,
    #[serde(default)]
    pub salary_cap: Option<f64>,
    /// Discord user ID of the primary GM (API sends as string).
    #[serde(rename = "gmid", default)]
    pub gm_discord_id: Option<String>,
    /// Discord user ID of the secondary GM (API sends as string).
    #[serde(rename = "gmid2", default)]
    pub gm2_discord_id: Option<String>,
    #[serde(default)]
    pub manager1: Option<Manager>,
    #[serde(default)]
    pub manager2: Option<Manager>,
    #[serde(default)]
    pub division: Option<Division>,
}

// =============================================================================
// Players
// =============================================================================

#[derive(Debug, Deserialize)]
pub struct PlayersResponse {
    pub count: u32,
    pub players: Vec<PlayerData>,
}

#[derive(Debug, Deserialize)]
pub struct PlayerData {
    pub id: i64,
    pub name: Option<String>,
    pub headshot: Option<String>,
    pub vanity_card: Option<String>,
    /// Strat-O-Matic WAR equivalent — API field is "wara".
    #[serde(rename = "wara", default)]
    pub swar: Option<f64>,
    /// SBA player ID — API field is "sbaplayer".
    #[serde(rename = "sbaplayer", default)]
    pub sbaplayer_id: Option<i64>,
    /// Primary card image URL — API field is "image".
    #[serde(rename = "image", default)]
    pub card_image: Option<String>,
    /// Alternate card image URL — API field is "image2".
    #[serde(rename = "image2", default)]
    pub card_image_alt: Option<String>,
    #[serde(default)]
    pub team: Option<TeamRef>,
    #[serde(default)]
    pub pos_1: Option<String>,
    #[serde(default)]
    pub pos_2: Option<String>,
    #[serde(default)]
    pub pos_3: Option<String>,
    #[serde(default)]
    pub pos_4: Option<String>,
    #[serde(default)]
    pub pos_5: Option<String>,
    #[serde(default)]
    pub pos_6: Option<String>,
    #[serde(default)]
    pub pos_7: Option<String>,
    #[serde(default)]
    pub pos_8: Option<String>,
    #[serde(default)]
    pub injury_rating: Option<String>,
    #[serde(default)]
    pub il_return: Option<String>,
    #[serde(default)]
    pub demotion_week: Option<i64>,
    #[serde(default)]
    pub strat_code: Option<String>,
    #[serde(default)]
    pub bbref_id: Option<String>,
    #[serde(default)]
    pub last_game: Option<String>,
    #[serde(default)]
    pub last_game2: Option<String>,
}

// =============================================================================
// Transactions
// =============================================================================

#[derive(Debug, Deserialize)]
pub struct TransactionsResponse {
    pub count: u32,
    pub transactions: Vec<TransactionData>,
}

#[derive(Debug, Deserialize)]
pub struct TransactionData {
    /// Transaction move ID — API field is "moveid" (string like "Season-013-Week-11-1772073335").
    #[serde(rename = "moveid", default)]
    pub move_id: Option<String>,
    #[serde(default)]
    pub week: Option<i64>,
    #[serde(default)]
    pub cancelled: Option<bool>,
    #[serde(default)]
    pub frozen: Option<bool>,
    #[serde(default)]
    pub player: Option<PlayerRef>,
    #[serde(default)]
    pub oldteam: Option<TeamRef>,
    #[serde(default)]
    pub newteam: Option<TeamRef>,
}

// =============================================================================
// Current season info
// =============================================================================

#[derive(Debug, Deserialize)]
pub struct CurrentResponse {
    pub season: i64,
    pub week: i64,
}
