//! This code was AUTOGENERATED using the Codama library.
use {crate::types::RewardInfo, solana_pubkey::Pubkey};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct PoolState {
    /// Bump to identify PDA
    pub bump: [u8; 1],
    pub amm_config: Pubkey,
    pub owner: Pubkey,
    /// Token pair of the pool, where token_mint_0 address < token_mint_1
    /// address
    pub token_mint0: Pubkey,
    pub token_mint1: Pubkey,
    /// Token pair vault
    pub token_vault0: Pubkey,
    pub token_vault1: Pubkey,
    /// observation account key
    pub observation_key: Pubkey,
    /// mint0 and mint1 decimals
    pub mint_decimals0: u8,
    pub mint_decimals1: u8,
    /// The minimum number of ticks between initialized ticks
    pub tick_spacing: u16,
    /// The currently in range liquidity available to the pool.
    pub liquidity: u128,
    /// The current price of the pool as a sqrt(token_1/token_0) Q64.64 value
    pub sqrt_price_x64: u128,
    /// The current tick of the pool, i.e. according to the last tick transition
    /// that was run.
    pub tick_current: i32,
    pub padding3: u16,
    pub padding4: u16,
    /// The fee growth as a Q64.64 number, i.e. fees of token_0 and token_1
    /// collected per unit of liquidity for the entire life of the pool.
    pub fee_growth_global0_x64: u128,
    pub fee_growth_global1_x64: u128,
    /// The amounts of token_0 and token_1 that are owed to the protocol.
    pub protocol_fees_token0: u64,
    pub protocol_fees_token1: u64,
    /// The amounts in and out of swap token_0 and token_1
    pub swap_in_amount_token0: u128,
    pub swap_out_amount_token1: u128,
    pub swap_in_amount_token1: u128,
    pub swap_out_amount_token0: u128,
    /// Bitwise representation of the state of the pool
    /// bit0, 1: disable open position and increase liquidity, 0: normal
    /// bit1, 1: disable decrease liquidity, 0: normal
    /// bit2, 1: disable collect fee, 0: normal
    /// bit3, 1: disable collect reward, 0: normal
    /// bit4, 1: disable swap, 0: normal
    pub status: u8,
    /// Leave blank for future use
    pub padding: [u8; 7],
    pub reward_infos: [RewardInfo; 3],
    /// Packed initialized tick array state
    pub tick_array_bitmap: [u64; 16],
    /// except protocol_fee and fund_fee
    pub total_fees_token0: u64,
    /// except protocol_fee and fund_fee
    pub total_fees_claimed_token0: u64,
    pub total_fees_token1: u64,
    pub total_fees_claimed_token1: u64,
    pub fund_fees_token0: u64,
    pub fund_fees_token1: u64,
    pub open_time: u64,
    pub recent_epoch: u64,
    pub padding1: [u64; 24],
    pub padding2: [u64; 32],
}

impl PoolState {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [247, 237, 227, 245, 215, 195, 222, 70] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
    }
}
