//! On-chain events (`sol_log_data` via Steel `event!` / `.log()`).
//!
//! The server and indexer subscribe to these events to maintain the off-chain state:
//! user balances, bet records, market outcomes, leaderboard history.
//!
//! ## Event contract
//!
//! | Event | Trigger | Observer action |
//! |---|---|---|
//! | `Deposited` | `Deposit` ix | Indexer credits user's off-chain USDC balance |
//! | `PeriodSettled` | `AdminInstantSettlement` | Bot computes + dispatches payouts; DB records outcome |
//! | `Paid` | `AdminPayout` | Bot confirms payout in DB |
//! | `Initialized` | `Initialize` | One-time setup confirmation |

use steel::*;

/// Emitted by `Initialize`.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Initialized {
    pub admin: Pubkey,
}

/// Emitted by `Deposit`. Server credits `user`'s off-chain balance by `amount` µUSDC.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Deposited {
    pub user: Pubkey,
    pub amount: u64,
}

/// Emitted by `AdminInstantSettlement`. Server reads this to compute and enqueue payouts.
///
/// `outcome` = `0` (UP) or `1` (DOWN).
/// `close_price` / `close_expo` / `close_publish_time` are the Pyth values read at settlement.
/// The open reference was `Treasury::last_close_*` immediately before this instruction ran.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct PeriodSettled {
    pub series_id: u16,
    pub outcome: u8,
    pub _pad: [u8; 5],
    pub period: u64,
    pub close_price: i64,
    pub close_expo: i32,
    pub _pad2: [u8; 4],
    pub close_publish_time: i64,
    /// Open reference price that was in Treasury before this settlement.
    pub open_price: i64,
    pub open_expo: i32,
    pub _pad3: [u8; 4],
}

/// Emitted by `AdminPayout`. Bot confirms the payout was delivered.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Paid {
    pub recipient: Pubkey,
    pub amount: u64,
    pub series_id: u16,
    pub _pad: [u8; 6],
    pub period: u64,
}

event!(Initialized);
event!(Deposited);
event!(PeriodSettled);
event!(Paid);
