use serde::{Deserialize, Serialize};
use steel::*;

use super::OilAccount;

/// Treasury is a singleton account which is the mint authority for the OIL token and the authority of
/// the program's global token account.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
pub struct Treasury {
    // The amount of SOL collected for buy-barrel operations.
    pub balance: u64,

    /// The amount of SOL in the gusher rewards pool.
    pub gusher_sol: u64,

    /// The cumulative OIL distributed to drillers, divided by the total unclaimed OIL at the time of distribution.
    pub driller_rewards_factor: Numeric,

    /// Buffer field (previously stake_rewards_factor, now in Pool).
    pub buffer_a: Numeric,

    /// The total amount of OIL barreled (burned) through buyback operations.
    pub total_barrelled: u64,

    /// The current total amount of refined OIL drilling rewards.
    pub total_refined: u64,

    /// The total amount of SOL held in treasury for auction rewards (to be claimed by drillers).
    pub auction_rewards_sol: u64,

    /// The current total amount of unclaimed OIL drilling rewards.
    pub total_unclaimed: u64,

    /// Auction-based mining: The cumulative OIL distributed to drillers, divided by the total unclaimed auction OIL at the time of distribution.
    pub auction_driller_rewards_factor: Numeric,

    /// Auction-based mining: The current total amount of unclaimed auction OIL drilling rewards.
    pub auction_total_unclaimed: u64,

    /// Auction-based mining: The current total amount of refined auction OIL drilling rewards.
    pub auction_total_refined: u64,
}

impl Treasury {
    /// Credit auction rewards SOL to treasury (tracks total SOL available for claiming)
    pub fn credit_auction_rewards_sol(&mut self, amount: u64) {
        self.auction_rewards_sol += amount;
    }
}

account!(OilAccount, Treasury);