//! 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 Swap {
    pub amount_in: u64,
    pub minimum_amount_out: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SwapInstructionAccounts {
    pub swap: solana_pubkey::Pubkey,
    pub authority: solana_pubkey::Pubkey,
    pub user_transfer_authority: solana_pubkey::Pubkey,
    pub source: solana_pubkey::Pubkey,
    pub swap_source: solana_pubkey::Pubkey,
    pub swap_destination: solana_pubkey::Pubkey,
    pub destination: solana_pubkey::Pubkey,
    pub pool_mint: solana_pubkey::Pubkey,
    pub pool_fee: solana_pubkey::Pubkey,
    pub source_mint: solana_pubkey::Pubkey,
    pub destination_mint: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub token_program_b: solana_pubkey::Pubkey,
    pub token_program_c: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for Swap {
    type ArrangedAccounts = SwapInstructionAccounts;

    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 = next_account(&mut iter)?;
        let swap_source = next_account(&mut iter)?;
        let swap_destination = next_account(&mut iter)?;
        let destination = next_account(&mut iter)?;
        let pool_mint = next_account(&mut iter)?;
        let pool_fee = next_account(&mut iter)?;
        let source_mint = next_account(&mut iter)?;
        let destination_mint = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;
        let token_program_b = next_account(&mut iter)?;
        let token_program_c = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(SwapInstructionAccounts {
            swap,
            authority,
            user_transfer_authority,
            source,
            swap_source,
            swap_destination,
            destination,
            pool_mint,
            pool_fee,
            source_mint,
            destination_mint,
            token_program,
            token_program_b,
            token_program_c,
            remaining: remaining.to_vec(),
        })
    }
}
