//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct DepositSingleTokenTypeExactAmountIn {
    pub source_token_amount: u64,
    pub minimum_pool_token_amount: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DepositSingleTokenTypeExactAmountInInstructionAccounts {
    pub swap: solana_pubkey::Pubkey,
    pub authority: solana_pubkey::Pubkey,
    pub user_transfer_authority: solana_pubkey::Pubkey,
    pub source_token: solana_pubkey::Pubkey,
    pub swap_token_a: solana_pubkey::Pubkey,
    pub swap_token_b: solana_pubkey::Pubkey,
    pub pool_mint: solana_pubkey::Pubkey,
    pub destination: solana_pubkey::Pubkey,
    pub source_mint: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub token_program_b: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl DepositSingleTokenTypeExactAmountIn {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.is_empty() {
            return None;
        }
        let discriminator = &data[0..1];
        if discriminator != [4] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for DepositSingleTokenTypeExactAmountIn {
    type ArrangedAccounts = DepositSingleTokenTypeExactAmountInInstructionAccounts;

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

        let swap = next_account(&mut iter)?;
        let authority = next_account(&mut iter)?;
        let user_transfer_authority = next_account(&mut iter)?;
        let source_token = next_account(&mut iter)?;
        let swap_token_a = next_account(&mut iter)?;
        let swap_token_b = next_account(&mut iter)?;
        let pool_mint = next_account(&mut iter)?;
        let destination = next_account(&mut iter)?;
        let source_mint = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;
        let token_program_b = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(DepositSingleTokenTypeExactAmountInInstructionAccounts {
            swap,
            authority,
            user_transfer_authority,
            source_token,
            swap_token_a,
            swap_token_b,
            pool_mint,
            destination,
            source_mint,
            token_program,
            token_program_b,
            remaining: remaining.to_vec(),
        })
    }
}
