//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::SwapArgs,
    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 SwapTobV3Enhanced {
    pub args: SwapArgs,
    pub commission_info: u32,
    pub trim_rate: u8,
    pub charge_rate: u16,
    pub platform_fee_rate: u16,
    pub order_id: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SwapTobV3EnhancedInstructionAccounts {
    pub payer: solana_pubkey::Pubkey,
    pub source_token_account: solana_pubkey::Pubkey,
    pub destination_token_account: solana_pubkey::Pubkey,
    pub source_mint: solana_pubkey::Pubkey,
    pub destination_mint: solana_pubkey::Pubkey,
    pub commission_account: Option<solana_pubkey::Pubkey>,
    pub platform_fee_account: Option<solana_pubkey::Pubkey>,
    pub sa_authority: Option<solana_pubkey::Pubkey>,
    pub source_token_sa: Option<solana_pubkey::Pubkey>,
    pub destination_token_sa: Option<solana_pubkey::Pubkey>,
    pub source_token_program: Option<solana_pubkey::Pubkey>,
    pub destination_token_program: Option<solana_pubkey::Pubkey>,
    pub associated_token_program: Option<solana_pubkey::Pubkey>,
    pub system_program: Option<solana_pubkey::Pubkey>,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl SwapTobV3Enhanced {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [236, 71, 155, 68, 198, 98, 14, 118] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for SwapTobV3Enhanced {
    type ArrangedAccounts = SwapTobV3EnhancedInstructionAccounts;

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

        let payer = next_account(&mut iter)?;
        let source_token_account = next_account(&mut iter)?;
        let destination_token_account = next_account(&mut iter)?;
        let source_mint = next_account(&mut iter)?;
        let destination_mint = next_account(&mut iter)?;
        let commission_account = next_account(&mut iter);
        let platform_fee_account = next_account(&mut iter);
        let sa_authority = next_account(&mut iter);
        let source_token_sa = next_account(&mut iter);
        let destination_token_sa = next_account(&mut iter);
        let source_token_program = next_account(&mut iter);
        let destination_token_program = next_account(&mut iter);
        let associated_token_program = next_account(&mut iter);
        let system_program = next_account(&mut iter);

        let remaining = iter.as_slice();

        Some(SwapTobV3EnhancedInstructionAccounts {
            payer,
            source_token_account,
            destination_token_account,
            source_mint,
            destination_mint,
            commission_account,
            platform_fee_account,
            sa_authority,
            source_token_sa,
            destination_token_sa,
            source_token_program,
            destination_token_program,
            associated_token_program,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}
