//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::DecompressV1Args,
    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 DecompressV1 {
    pub decompress_v1_args: DecompressV1Args,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DecompressV1InstructionAccounts {
    pub asset: solana_pubkey::Pubkey,
    pub collection: Option<solana_pubkey::Pubkey>,
    pub payer: solana_pubkey::Pubkey,
    pub authority: Option<solana_pubkey::Pubkey>,
    pub system_program: solana_pubkey::Pubkey,
    pub log_wrapper: Option<solana_pubkey::Pubkey>,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for DecompressV1 {
    type ArrangedAccounts = DecompressV1InstructionAccounts;

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

        let asset = next_account(&mut iter)?;
        let collection = next_account(&mut iter);
        let payer = next_account(&mut iter)?;
        let authority = next_account(&mut iter);
        let system_program = next_account(&mut iter)?;
        let log_wrapper = next_account(&mut iter);

        let remaining = iter.as_slice();

        Some(DecompressV1InstructionAccounts {
            asset,
            collection,
            payer,
            authority,
            system_program,
            log_wrapper,
            remaining: remaining.to_vec(),
        })
    }
}
