//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use borsh::BorshSerialize;
use borsh::BorshDeserialize;

pub const SET_POSITION_RANGE_DISCRIMINATOR: [u8; 8] = [192, 22, 176, 176, 155, 49, 153, 96];

/// Accounts.
#[derive(Debug)]
pub struct SetPositionRange {
      
              
          pub position_authority: solana_pubkey::Pubkey,
          
              
          pub position: solana_pubkey::Pubkey,
          
              
          pub position_token_account: solana_pubkey::Pubkey,
          
              
          pub fusion_pool: solana_pubkey::Pubkey,
      }

impl SetPositionRange {
  pub fn instruction(&self, args: SetPositionRangeInstructionArgs) -> solana_instruction::Instruction {
    self.instruction_with_remaining_accounts(args, &[])
  }
  #[allow(clippy::arithmetic_side_effects)]
  #[allow(clippy::vec_init_then_push)]
  pub fn instruction_with_remaining_accounts(&self, args: SetPositionRangeInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
    let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
                            accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.position_authority,
            true
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.position,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.position_token_account,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.fusion_pool,
            false
          ));
                      accounts.extend_from_slice(remaining_accounts);
    let mut data = borsh::to_vec(&SetPositionRangeInstructionData::new()).unwrap();
          let mut args = borsh::to_vec(&args).unwrap();
      data.append(&mut args);
    
    solana_instruction::Instruction {
      program_id: crate::FUSIONAMM_ID,
      accounts,
      data,
    }
  }
}

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
 pub struct SetPositionRangeInstructionData {
            discriminator: [u8; 8],
                  }

impl SetPositionRangeInstructionData {
  pub fn new() -> Self {
    Self {
                        discriminator: [192, 22, 176, 176, 155, 49, 153, 96],
                                              }
  }
}

impl Default for SetPositionRangeInstructionData {
  fn default() -> Self {
    Self::new()
  }
}

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
 pub struct SetPositionRangeInstructionArgs {
                  pub tick_lower_index: i32,
                pub tick_upper_index: i32,
      }


/// Instruction builder for `SetPositionRange`.
///
/// ### Accounts:
///
                ///   0. `[signer]` position_authority
                ///   1. `[writable]` position
                ///   2. `[writable]` position_token_account
          ///   3. `[]` fusion_pool
#[derive(Clone, Debug, Default)]
pub struct SetPositionRangeBuilder {
            position_authority: Option<solana_pubkey::Pubkey>,
                position: Option<solana_pubkey::Pubkey>,
                position_token_account: Option<solana_pubkey::Pubkey>,
                fusion_pool: Option<solana_pubkey::Pubkey>,
                        tick_lower_index: Option<i32>,
                tick_upper_index: Option<i32>,
        __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl SetPositionRangeBuilder {
  pub fn new() -> Self {
    Self::default()
  }
            #[inline(always)]
    pub fn position_authority(&mut self, position_authority: solana_pubkey::Pubkey) -> &mut Self {
                        self.position_authority = Some(position_authority);
                    self
    }
            #[inline(always)]
    pub fn position(&mut self, position: solana_pubkey::Pubkey) -> &mut Self {
                        self.position = Some(position);
                    self
    }
            #[inline(always)]
    pub fn position_token_account(&mut self, position_token_account: solana_pubkey::Pubkey) -> &mut Self {
                        self.position_token_account = Some(position_token_account);
                    self
    }
            #[inline(always)]
    pub fn fusion_pool(&mut self, fusion_pool: solana_pubkey::Pubkey) -> &mut Self {
                        self.fusion_pool = Some(fusion_pool);
                    self
    }
                    #[inline(always)]
      pub fn tick_lower_index(&mut self, tick_lower_index: i32) -> &mut Self {
        self.tick_lower_index = Some(tick_lower_index);
        self
      }
                #[inline(always)]
      pub fn tick_upper_index(&mut self, tick_upper_index: i32) -> &mut Self {
        self.tick_upper_index = Some(tick_upper_index);
        self
      }
        /// Add an additional account to the instruction.
  #[inline(always)]
  pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
    self.__remaining_accounts.push(account);
    self
  }
  /// Add additional accounts to the instruction.
  #[inline(always)]
  pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
    self.__remaining_accounts.extend_from_slice(accounts);
    self
  }
  #[allow(clippy::clone_on_copy)]
  pub fn instruction(&self) -> solana_instruction::Instruction {
    let accounts = SetPositionRange {
                              position_authority: self.position_authority.expect("position_authority is not set"),
                                        position: self.position.expect("position is not set"),
                                        position_token_account: self.position_token_account.expect("position_token_account is not set"),
                                        fusion_pool: self.fusion_pool.expect("fusion_pool is not set"),
                      };
          let args = SetPositionRangeInstructionArgs {
                                                              tick_lower_index: self.tick_lower_index.clone().expect("tick_lower_index is not set"),
                                                                  tick_upper_index: self.tick_upper_index.clone().expect("tick_upper_index is not set"),
                                    };
    
    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
  }
}

  /// `set_position_range` CPI accounts.
  pub struct SetPositionRangeCpiAccounts<'a, 'b> {
          
                    
              pub position_authority: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub position: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub position_token_account: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub fusion_pool: &'b solana_account_info::AccountInfo<'a>,
            }

/// `set_position_range` CPI instruction.
pub struct SetPositionRangeCpi<'a, 'b> {
  /// The program to invoke.
  pub __program: &'b solana_account_info::AccountInfo<'a>,
      
              
          pub position_authority: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub position: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub position_token_account: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub fusion_pool: &'b solana_account_info::AccountInfo<'a>,
            /// The arguments for the instruction.
    pub __args: SetPositionRangeInstructionArgs,
  }

impl<'a, 'b> SetPositionRangeCpi<'a, 'b> {
  pub fn new(
    program: &'b solana_account_info::AccountInfo<'a>,
          accounts: SetPositionRangeCpiAccounts<'a, 'b>,
              args: SetPositionRangeInstructionArgs,
      ) -> Self {
    Self {
      __program: program,
              position_authority: accounts.position_authority,
              position: accounts.position,
              position_token_account: accounts.position_token_account,
              fusion_pool: accounts.fusion_pool,
                    __args: args,
          }
  }
  #[inline(always)]
  pub fn invoke(&self) -> solana_program_error::ProgramResult {
    self.invoke_signed_with_remaining_accounts(&[], &[])
  }
  #[inline(always)]
  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
    self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
  }
  #[inline(always)]
  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
    self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
  }
  #[allow(clippy::arithmetic_side_effects)]
  #[allow(clippy::clone_on_copy)]
  #[allow(clippy::vec_init_then_push)]
  pub fn invoke_signed_with_remaining_accounts(
    &self,
    signers_seeds: &[&[&[u8]]],
    remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
  ) -> solana_program_error::ProgramResult {
    let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
                            accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.position_authority.key,
            true
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.position.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.position_token_account.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.fusion_pool.key,
            false
          ));
                      remaining_accounts.iter().for_each(|remaining_account| {
      accounts.push(solana_instruction::AccountMeta {
          pubkey: *remaining_account.0.key,
          is_signer: remaining_account.1,
          is_writable: remaining_account.2,
      })
    });
    let mut data = borsh::to_vec(&SetPositionRangeInstructionData::new()).unwrap();
          let mut args = borsh::to_vec(&self.__args).unwrap();
      data.append(&mut args);
    
    let instruction = solana_instruction::Instruction {
      program_id: crate::FUSIONAMM_ID,
      accounts,
      data,
    };
    let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
    account_infos.push(self.__program.clone());
                  account_infos.push(self.position_authority.clone());
                        account_infos.push(self.position.clone());
                        account_infos.push(self.position_token_account.clone());
                        account_infos.push(self.fusion_pool.clone());
              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));

    if signers_seeds.is_empty() {
      solana_cpi::invoke(&instruction, &account_infos)
    } else {
      solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
    }
  }
}

/// Instruction builder for `SetPositionRange` via CPI.
///
/// ### Accounts:
///
                ///   0. `[signer]` position_authority
                ///   1. `[writable]` position
                ///   2. `[writable]` position_token_account
          ///   3. `[]` fusion_pool
#[derive(Clone, Debug)]
pub struct SetPositionRangeCpiBuilder<'a, 'b> {
  instruction: Box<SetPositionRangeCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> SetPositionRangeCpiBuilder<'a, 'b> {
  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
    let instruction = Box::new(SetPositionRangeCpiBuilderInstruction {
      __program: program,
              position_authority: None,
              position: None,
              position_token_account: None,
              fusion_pool: None,
                                            tick_lower_index: None,
                                tick_upper_index: None,
                    __remaining_accounts: Vec::new(),
    });
    Self { instruction }
  }
      #[inline(always)]
    pub fn position_authority(&mut self, position_authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.position_authority = Some(position_authority);
                    self
    }
      #[inline(always)]
    pub fn position(&mut self, position: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.position = Some(position);
                    self
    }
      #[inline(always)]
    pub fn position_token_account(&mut self, position_token_account: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.position_token_account = Some(position_token_account);
                    self
    }
      #[inline(always)]
    pub fn fusion_pool(&mut self, fusion_pool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.fusion_pool = Some(fusion_pool);
                    self
    }
                    #[inline(always)]
      pub fn tick_lower_index(&mut self, tick_lower_index: i32) -> &mut Self {
        self.instruction.tick_lower_index = Some(tick_lower_index);
        self
      }
                #[inline(always)]
      pub fn tick_upper_index(&mut self, tick_upper_index: i32) -> &mut Self {
        self.instruction.tick_upper_index = Some(tick_upper_index);
        self
      }
        /// Add an additional account to the instruction.
  #[inline(always)]
  pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
    self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
    self
  }
  /// Add additional accounts to the instruction.
  ///
  /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
  /// and a `bool` indicating whether the account is a signer or not.
  #[inline(always)]
  pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
    self.instruction.__remaining_accounts.extend_from_slice(accounts);
    self
  }
  #[inline(always)]
  pub fn invoke(&self) -> solana_program_error::ProgramResult {
    self.invoke_signed(&[])
  }
  #[allow(clippy::clone_on_copy)]
  #[allow(clippy::vec_init_then_push)]
  pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
          let args = SetPositionRangeInstructionArgs {
                                                              tick_lower_index: self.instruction.tick_lower_index.clone().expect("tick_lower_index is not set"),
                                                                  tick_upper_index: self.instruction.tick_upper_index.clone().expect("tick_upper_index is not set"),
                                    };
        let instruction = SetPositionRangeCpi {
        __program: self.instruction.__program,
                  
          position_authority: self.instruction.position_authority.expect("position_authority is not set"),
                  
          position: self.instruction.position.expect("position is not set"),
                  
          position_token_account: self.instruction.position_token_account.expect("position_token_account is not set"),
                  
          fusion_pool: self.instruction.fusion_pool.expect("fusion_pool is not set"),
                          __args: args,
            };
    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
  }
}

#[derive(Clone, Debug)]
struct SetPositionRangeCpiBuilderInstruction<'a, 'b> {
  __program: &'b solana_account_info::AccountInfo<'a>,
            position_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
                position: Option<&'b solana_account_info::AccountInfo<'a>>,
                position_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
                fusion_pool: Option<&'b solana_account_info::AccountInfo<'a>>,
                        tick_lower_index: Option<i32>,
                tick_upper_index: Option<i32>,
        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}

