//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::InitializeRewardParam,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// Initialize a reward info for a given pool and reward index
/// # Arguments
/// * `ctx`- The context of accounts
/// * `reward_index` - the index to reward info
/// * `open_time` - reward open timestamp
/// * `end_time` - reward end timestamp
/// * `emissions_per_second_x64` - Token reward per second are earned per unit
///   of liquidity.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct InitializeReward {
    pub param: InitializeRewardParam,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InitializeRewardInstructionAccounts {
    pub reward_funder: solana_pubkey::Pubkey,
    pub funder_token_account: solana_pubkey::Pubkey,
    pub amm_config: solana_pubkey::Pubkey,
    pub pool_state: solana_pubkey::Pubkey,
    pub operation_state: solana_pubkey::Pubkey,
    pub permissionless_farm_switch: solana_pubkey::Pubkey,
    pub reward_token_mint: solana_pubkey::Pubkey,
    pub reward_token_vault: solana_pubkey::Pubkey,
    pub reward_token_program: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub rent: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl InitializeReward {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [95, 135, 192, 196, 242, 129, 230, 68] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for InitializeReward {
    type ArrangedAccounts = InitializeRewardInstructionAccounts;

    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 amm_config = next_account(&mut iter)?;
        let pool_state = next_account(&mut iter)?;
        let operation_state = next_account(&mut iter)?;
        let permissionless_farm_switch = next_account(&mut iter)?;
        let reward_token_mint = next_account(&mut iter)?;
        let reward_token_vault = next_account(&mut iter)?;
        let reward_token_program = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;
        let rent = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(InitializeRewardInstructionAccounts {
            reward_funder,
            funder_token_account,
            amm_config,
            pool_state,
            operation_state,
            permissionless_farm_switch,
            reward_token_mint,
            reward_token_vault,
            reward_token_program,
            system_program,
            rent,
            remaining: remaining.to_vec(),
        })
    }
}
