//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Collect remaining reward token for reward founder
/// # Arguments
/// * `ctx`- The context of accounts
/// * `reward_index` - the index to reward info
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct CollectRemainingRewards {
    pub reward_index: u8,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CollectRemainingRewardsInstructionAccounts {
    pub reward_funder: solana_pubkey::Pubkey,
    pub funder_token_account: solana_pubkey::Pubkey,
    pub pool_state: solana_pubkey::Pubkey,
    pub reward_token_vault: solana_pubkey::Pubkey,
    pub reward_vault_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 CollectRemainingRewards {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [18, 237, 166, 197, 34, 16, 213, 144] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for CollectRemainingRewards {
    type ArrangedAccounts = CollectRemainingRewardsInstructionAccounts;

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

        let reward_funder = next_account(&mut iter)?;
        let funder_token_account = next_account(&mut iter)?;
        let pool_state = next_account(&mut iter)?;
        let reward_token_vault = next_account(&mut iter)?;
        let reward_vault_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(CollectRemainingRewardsInstructionAccounts {
            reward_funder,
            funder_token_account,
            pool_state,
            reward_token_vault,
            reward_vault_mint,
            token_program,
            token_program2022,
            memo_program,
            remaining: remaining.to_vec(),
        })
    }
}
