//! This code was AUTOGENERATED using the Codama library.
use {
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
    solana_pubkey::Pubkey,
};
/// Update the operation account
/// # Arguments
/// * `ctx`- The context of accounts
/// * `param`- The value can be 0 | 1 | 2 | 3, otherwise will report a error
/// * `keys`- update operation owner when the `param` is 0
///
/// remove operation owner when the `param` is 1
/// update whitelist mint when the `param` is 2
/// remove whitelist mint when the `param` is 3
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct UpdateOperationAccount {
    pub param: u8,
    pub keys: Vec<Pubkey>,
}

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

impl UpdateOperationAccount {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [127, 70, 119, 40, 188, 227, 61, 7] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for UpdateOperationAccount {
    type ArrangedAccounts = UpdateOperationAccountInstructionAccounts;

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

        let owner = next_account(&mut iter)?;
        let operation_state = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(UpdateOperationAccountInstructionAccounts {
            owner,
            operation_state,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}
