//! One stake per trader per **`Market::period`** (**`PlaceBet`** creates / tops up). PDA: [`position_pda`](super::position_pda).

use steel::*;

use super::{position_pda, StreakAccount};

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Position {
    pub authority: Pubkey,
    pub period: u64,
    pub stake: u64,
    /// [`Market::SIDE_UP`](super::Market::SIDE_UP) or [`Market::SIDE_DOWN`](super::Market::SIDE_DOWN); matches [`Market::outcome`] after settle.
    pub side: u8,
    /// [`Self::STATE_PENDING`], [`Self::STATE_CLAIMED_WIN`], or [`Self::STATE_FINALIZED_LOSS`].
    pub state: u8,
    pub _pad: [u8; 6],
}

impl Position {
    /// Open (**`PlaceBet`** may add stake until settle).
    pub const STATE_PENDING: u8 = 0;

    /// Winner paid via **`ExecutorTreasury`** (**distribute**) (**executor**).
    pub const STATE_CLAIMED_WIN: u8 = 1;

    /// Loser bookkeeping: the next period’s **`BuyTickets`** or **`PlaceBet`** finalizes this after settlement.
    pub const STATE_FINALIZED_LOSS: u8 = 2;

    pub fn pda(period: u64, authority: Pubkey) -> (Pubkey, u8) {
        position_pda(period, authority)
    }
}

account!(StreakAccount, Position);
