//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Updates the owner of the amm config
/// Must be called by the current owner or admin
/// # Arguments
/// * `ctx`- The context of accounts
/// * `trade_fee_rate`- The new trade fee rate of amm config, be set when
///   `param` is 0
/// * `protocol_fee_rate`- The new protocol fee rate of amm config, be set when
///   `param` is 1
/// * `fund_fee_rate`- The new fund fee rate of amm config, be set when `param`
///   is 2
/// * `new_owner`- The config's new owner, be set when `param` is 3
/// * `new_fund_owner`- The config's new fund owner, be set when `param` is 4
/// * `param`- The value can be 0 | 1 | 2 | 3 | 4, otherwise will report a error
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct UpdateAmmConfig {
    pub param: u8,
    pub value: u32,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpdateAmmConfigInstructionAccounts {
    pub owner: solana_pubkey::Pubkey,
    pub amm_config: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl UpdateAmmConfig {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [49, 60, 174, 136, 154, 28, 116, 200] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for UpdateAmmConfig {
    type ArrangedAccounts = UpdateAmmConfigInstructionAccounts;

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

        let owner = next_account(&mut iter)?;
        let amm_config = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(UpdateAmmConfigInstructionAccounts {
            owner,
            amm_config,
            remaining: remaining.to_vec(),
        })
    }
}
