//! Per-player **`unstaked_micros`** / **`tickets`** plus [**`Market`**](crate::state::Market) win streak (`ledger` PDA).

use steel::*;

use super::{ledger_pda, StreakAccount};

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Ledger {
    pub authority: Pubkey,
    /// Whole tickets credited on **`BuyTickets`**: post–team remainder divided by [`TICKET_MICROS`](crate::consts::TICKET_MICROS) (integer division).
    pub tickets: u64,
    /// Post–team-cut USDC (base units) credited on **`BuyTickets`** and debited when spending tickets on **`PlaceBet`**.
    pub unstaked_micros: u64,
    /// Consecutive winning periods after **`ExecutorTreasury`** (**distribute**); used **off‑chain** for leaderboard. Cleared when a settled loss is rolled in on **`BuyTickets`** / **`PlaceBet`** for the following period (or **`Initialize`**/`Ledger` create path).
    pub win_streak: u64,
    /// Last period the user successfully claimed as a winner; `0` = none.
    pub last_win_period: u64,
}

impl Ledger {
    pub fn pda(authority: Pubkey) -> (Pubkey, u8) {
        ledger_pda(authority)
    }
}

account!(StreakAccount, Ledger);
