//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Toggle the permissionless farm switch account
/// # Arguments
/// * `ctx`- The context of accounts
/// * `is_on`- Is the permissionless farm allowed or not
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct TogglePermissionlessFarmSwitch {
    pub is_on: bool,
}

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

impl TogglePermissionlessFarmSwitch {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [150, 112, 54, 233, 238, 161, 7, 86] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for TogglePermissionlessFarmSwitch {
    type ArrangedAccounts = TogglePermissionlessFarmSwitchInstructionAccounts;

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

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

        let remaining = iter.as_slice();

        Some(TogglePermissionlessFarmSwitchInstructionAccounts {
            owner,
            permissionless_farm_switch,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}
