//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::{Fees, SwapCurve},
    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 Initialize {
    pub fees: Fees,
    pub swap_curve: SwapCurve,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InitializeInstructionAccounts {
    pub swap: solana_pubkey::Pubkey,
    pub authority: solana_pubkey::Pubkey,
    pub token_a: solana_pubkey::Pubkey,
    pub token_b: solana_pubkey::Pubkey,
    pub pool: solana_pubkey::Pubkey,
    pub fee: solana_pubkey::Pubkey,
    pub destination: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for Initialize {
    type ArrangedAccounts = InitializeInstructionAccounts;

    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 token_a = next_account(&mut iter)?;
        let token_b = next_account(&mut iter)?;
        let pool = next_account(&mut iter)?;
        let fee = next_account(&mut iter)?;
        let destination = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(InitializeInstructionAccounts {
            swap,
            authority,
            token_a,
            token_b,
            pool,
            fee,
            destination,
            token_program,
            remaining: remaining.to_vec(),
        })
    }
}
