//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Swap token for as much as possible of another token across the path
/// provided, base input # Arguments
/// * `ctx` - The context of accounts
/// * `amount_in` - Token amount to be swapped in
/// * `amount_out_minimum` - Panic if output amount is below minimum amount. For
///   slippage.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct SwapRouterBaseIn {
    pub amount_in: u64,
    pub amount_out_minimum: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SwapRouterBaseInInstructionAccounts {
    pub payer: solana_pubkey::Pubkey,
    pub input_token_account: solana_pubkey::Pubkey,
    pub input_token_mint: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub token_program2022: solana_pubkey::Pubkey,
    pub memo_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl SwapRouterBaseIn {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [69, 125, 115, 218, 245, 186, 242, 196] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for SwapRouterBaseIn {
    type ArrangedAccounts = SwapRouterBaseInInstructionAccounts;

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

        let payer = next_account(&mut iter)?;
        let input_token_account = next_account(&mut iter)?;
        let input_token_mint = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;
        let token_program2022 = next_account(&mut iter)?;
        let memo_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(SwapRouterBaseInInstructionAccounts {
            payer,
            input_token_account,
            input_token_mint,
            token_program,
            token_program2022,
            memo_program,
            remaining: remaining.to_vec(),
        })
    }
}
