//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Collect the protocol fee accrued to the pool
/// # Arguments
/// * `ctx` - The context of accounts
/// * `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to
///   collect fees in only token_1
/// * `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to
///   collect fees in only token_0
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct CollectProtocolFee {
    pub amount0_requested: u64,
    pub amount1_requested: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CollectProtocolFeeInstructionAccounts {
    pub owner: solana_pubkey::Pubkey,
    pub pool_state: solana_pubkey::Pubkey,
    pub amm_config: solana_pubkey::Pubkey,
    pub token_vault0: solana_pubkey::Pubkey,
    pub token_vault1: solana_pubkey::Pubkey,
    pub vault0_mint: solana_pubkey::Pubkey,
    pub vault1_mint: solana_pubkey::Pubkey,
    pub recipient_token_account0: solana_pubkey::Pubkey,
    pub recipient_token_account1: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub token_program2022: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl CollectProtocolFee {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [136, 136, 252, 221, 194, 66, 126, 89] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for CollectProtocolFee {
    type ArrangedAccounts = CollectProtocolFeeInstructionAccounts;

    fn arrange_accounts(
        accounts: &[solana_instruction::AccountMeta],
    ) -> Option<Self::ArrangedAccounts> {
        let mut iter = accounts.iter();

        let owner = next_account(&mut iter)?;
        let pool_state = next_account(&mut iter)?;
        let amm_config = next_account(&mut iter)?;
        let token_vault0 = next_account(&mut iter)?;
        let token_vault1 = next_account(&mut iter)?;
        let vault0_mint = next_account(&mut iter)?;
        let vault1_mint = next_account(&mut iter)?;
        let recipient_token_account0 = next_account(&mut iter)?;
        let recipient_token_account1 = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;
        let token_program2022 = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(CollectProtocolFeeInstructionAccounts {
            owner,
            pool_state,
            amm_config,
            token_vault0,
            token_vault1,
            vault0_mint,
            vault1_mint,
            recipient_token_account0,
            recipient_token_account1,
            token_program,
            token_program2022,
            remaining: remaining.to_vec(),
        })
    }
}
