//! This code was AUTOGENERATED using the Codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun Codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use crate::types::FixedPoint;
use crate::types::Product;
use crate::types::Token;
use carbon_core::borsh::{self, BorshDeserialize};
use solana_pubkey::Pubkey;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(
    Debug,
    Clone,
    carbon_core::borsh::BorshSerialize,
    carbon_core::borsh::BorshDeserialize,
    PartialEq,
)]
pub struct Pool {
    pub token_x: Pubkey,
    pub token_y: Pubkey,
    pub pool_x_account: Pubkey,
    pub pool_y_account: Pubkey,
    pub admin: Pubkey,
    pub project_owner: Pubkey,
    pub token_x_reserve: Token,
    pub token_y_reserve: Token,
    pub self_shares: Token,
    pub all_shares: Token,
    pub buyback_amount_x: Token,
    pub buyback_amount_y: Token,
    pub project_amount_x: Token,
    pub project_amount_y: Token,
    pub mercanti_amount_x: Token,
    pub mercanti_amount_y: Token,
    pub lp_accumulator_x: FixedPoint,
    pub lp_accumulator_y: FixedPoint,
    pub const_k: Product,
    pub price: FixedPoint,
    pub lp_fee: FixedPoint,
    pub buyback_fee: FixedPoint,
    pub project_fee: FixedPoint,
    pub mercanti_fee: FixedPoint,
    pub farm_count: u64,
    pub bump: u8,
}

impl Pool {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [241, 154, 109, 4, 17, 177, 109, 188] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

        if let Ok(decoded) = Self::deserialize(&mut data_slice) {
            return Some(decoded);
        }

        None
    }
}
