//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// #[deprecated(note = "Use `decrease_liquidity_v2` instead.")]
/// Decreases liquidity for an existing position
/// # Arguments
/// * `ctx` -  The context of accounts
/// * `liquidity` - The amount by which liquidity will be decreased
/// * `amount_0_min` - The minimum amount of token_0 that should be accounted
///   for the burned liquidity
/// * `amount_1_min` - The minimum amount of token_1 that should be accounted
///   for the burned liquidity
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct DecreaseLiquidity {
    pub liquidity: u128,
    pub amount0_min: u64,
    pub amount1_min: u64,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DecreaseLiquidityInstructionAccounts {
    pub nft_owner: solana_pubkey::Pubkey,
    pub nft_account: solana_pubkey::Pubkey,
    pub personal_position: solana_pubkey::Pubkey,
    pub pool_state: solana_pubkey::Pubkey,
    pub protocol_position: solana_pubkey::Pubkey,
    pub token_vault0: solana_pubkey::Pubkey,
    pub token_vault1: solana_pubkey::Pubkey,
    pub tick_array_lower: solana_pubkey::Pubkey,
    pub tick_array_upper: solana_pubkey::Pubkey,
    pub recipient_token_account0: solana_pubkey::Pubkey,
    pub recipient_token_account1: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl DecreaseLiquidity {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [160, 38, 208, 111, 104, 91, 44, 1] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for DecreaseLiquidity {
    type ArrangedAccounts = DecreaseLiquidityInstructionAccounts;

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

        let nft_owner = next_account(&mut iter)?;
        let nft_account = next_account(&mut iter)?;
        let personal_position = next_account(&mut iter)?;
        let pool_state = next_account(&mut iter)?;
        let protocol_position = next_account(&mut iter)?;
        let token_vault0 = next_account(&mut iter)?;
        let token_vault1 = next_account(&mut iter)?;
        let tick_array_lower = next_account(&mut iter)?;
        let tick_array_upper = next_account(&mut iter)?;
        let recipient_token_account0 = next_account(&mut iter)?;
        let recipient_token_account1 = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(DecreaseLiquidityInstructionAccounts {
            nft_owner,
            nft_account,
            personal_position,
            pool_state,
            protocol_position,
            token_vault0,
            token_vault1,
            tick_array_lower,
            tick_array_upper,
            recipient_token_account0,
            recipient_token_account1,
            token_program,
            remaining: remaining.to_vec(),
        })
    }
}
