//! 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 Claim {}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ClaimInstructionAccounts {
    pub signer: solana_pubkey::Pubkey,
    pub receiver: solana_pubkey::Pubkey,
    pub source_token_account: Option<solana_pubkey::Pubkey>,
    pub destination_token_account: Option<solana_pubkey::Pubkey>,
    pub sa_authority: solana_pubkey::Pubkey,
    pub token_mint: Option<solana_pubkey::Pubkey>,
    pub token_program: Option<solana_pubkey::Pubkey>,
    pub system_program: solana_pubkey::Pubkey,
    pub associated_token_program: Option<solana_pubkey::Pubkey>,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl Claim {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [62, 198, 214, 193, 213, 159, 108, 210] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for Claim {
    type ArrangedAccounts = ClaimInstructionAccounts;

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

        let signer = next_account(&mut iter)?;
        let receiver = next_account(&mut iter)?;
        let source_token_account = next_account(&mut iter);
        let destination_token_account = next_account(&mut iter);
        let sa_authority = next_account(&mut iter)?;
        let token_mint = next_account(&mut iter);
        let token_program = next_account(&mut iter);
        let system_program = next_account(&mut iter)?;
        let associated_token_program = next_account(&mut iter);

        let remaining = iter.as_slice();

        Some(ClaimInstructionAccounts {
            signer,
            receiver,
            source_token_account,
            destination_token_account,
            sa_authority,
            token_mint,
            token_program,
            system_program,
            associated_token_program,
            remaining: remaining.to_vec(),
        })
    }
}
