use steel::*;

#[repr(u32)]
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)]
pub enum StreakError {
    #[error("Invalid instruction data")]
    InvalidInstruction = 0,
    #[error("Program already initialized")]
    AlreadyInitialized = 1,
    #[error("Signer is not authorized for this ix")]
    Unauthorized = 2,
    #[error("Account does not match expected PDA")]
    BadPda = 3,
    #[error("Instruction requires an initialized config")]
    NotInitialized = 4,
    #[error("Arithmetic overflow")]
    Overflow = 5,
    #[error("Mint mismatch")]
    BadMint = 6,
    #[error("Treasury balance insufficient")]
    InsufficientTreasury = 9,
    #[error("Amount must be a whole-ticket multiple")]
    BadTicketUnit = 10,
    #[error("Market is not in the expected state")]
    BadMarketState = 12,
    #[error("Betting window is closed or not open yet")]
    BettingClosed = 13,
    #[error("Trader already has a position for this period")]
    DuplicatePosition = 14,
    #[error("Position already finalized")]
    PositionAlreadyHandled = 15,
    #[error("Trader is not on the winning side")]
    NotAWinner = 16,
    #[error("Cannot subsidize winners when no winning stake")]
    EmptyWinningSide = 17,
    #[error("Unknown treasury pay pool / lane")]
    InvalidTreasuryPayPool = 18,
    #[error("Not enough ticket balance for this bet")]
    InsufficientTickets = 19,
    #[error("Ledger missing; buy tickets first")]
    LedgerNotReady = 20,
    #[error("Price account owner is not the configured Pyth program")]
    PythBadOwner = 21,
    #[error("Could not parse Pyth price account")]
    PythInvalidAccount = 22,
    #[error("Pyth price is stale for the configured max age")]
    OraclePriceStale = 23,
    #[error("Could not normalize oracle prices for comparison")]
    OracleNormalize = 24,
    #[error("Oracle open and close prices tie at resolved precision (reserved; ties settle as DOWN)")]
    OracleParityTie = 25,
    #[error("Market missing open Pyth anchor; rerun InitMarket in the anchor window after open_ts (matching open_ts / close_ts / pyth feed / rules_hash)")]
    MarketNotOracleAnchored = 26,
    #[error("Pyth feed pubkey must be non-default on Market INIT")]
    InvalidPythPriceFeed = 30,
    #[error("InitMarket crank before Market::open_ts")]
    AnchorTooEarly = 31,
    #[error("InitMarket crank after grace window for this bucket")]
    AnchorWindowExpired = 32,
    #[error("PlaceBet requires InitMarket-open anchor before staking")]
    MarketNotAnchoredYet = 33,
    #[error("Market open snapshot already recorded (InitMarket crank is idempotent-complete)")]
    MarketAlreadyAnchored = 34,
    #[error("ExecutorTreasury instruction kind byte is invalid")]
    InvalidExecutorTreasuryKind = 35,
    #[error("ExecutorTreasury DISTRIBUTE branch requires pool=0 and amount=0")]
    InvalidExecutorTreasuryPayload = 36,
    #[error("InitMarket create requires period == treasury.next_market_period (prior period must settle first)")]
    WrongMarketSequenceForCreate = 37,
    #[error("PlaceBet only allowed on treasury.next_market_period (active market line)")]
    BetWrongMarketPeriod = 38,
    #[error("MARKET_LINE_RELEASE: market not settled or line already advanced")]
    MarketLineReleaseInvalid = 39,
}

error!(StreakError);
