//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Reset reward param, start a new reward cycle or extend the current cycle.
/// # Arguments
/// * `ctx` - The context of accounts
/// * `reward_index` - The index of reward token in the pool.
/// * `emissions_per_second_x64` - The per second emission reward, when extend
///   the current cycle,
///
/// new value can't be less than old value
/// * `open_time` - reward open timestamp, must be set when starting a new cycle
/// * `end_time` - reward end timestamp
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct SetRewardParams {
    pub reward_index: u8,
    pub emissions_per_second_x64: u128,
    pub open_time: u64,
    pub end_time: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SetRewardParamsInstructionAccounts {
    pub authority: solana_pubkey::Pubkey,
    pub amm_config: solana_pubkey::Pubkey,
    pub pool_state: solana_pubkey::Pubkey,
    pub operation_state: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub token_program2022: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl SetRewardParams {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [112, 52, 167, 75, 32, 201, 211, 137] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for SetRewardParams {
    type ArrangedAccounts = SetRewardParamsInstructionAccounts;

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

        let authority = 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 token_program = next_account(&mut iter)?;
        let token_program2022 = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(SetRewardParamsInstructionAccounts {
            authority,
            amm_config,
            pool_state,
            operation_state,
            token_program,
            token_program2022,
            remaining: remaining.to_vec(),
        })
    }
}
