//! 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 crate::generated::types::PositionLockType;
use borsh::BorshSerialize;
use borsh::BorshDeserialize;

pub const LOCK_LP_POSITION_FUSION_DISCRIMINATOR: [u8; 8] = [231, 87, 69, 13, 113, 64, 173, 208];

/// Accounts.
#[derive(Debug)]
pub struct LockLpPositionFusion {
      
              
          pub authority: solana_pubkey::Pubkey,
          
              
          pub tuna_position: solana_pubkey::Pubkey,
          
              
          pub tuna_position_ata: solana_pubkey::Pubkey,
          
              
          pub tuna_position_mint: solana_pubkey::Pubkey,
                /// 
/// Fusion accounts
/// 

    
              
          pub fusionamm_program: solana_pubkey::Pubkey,
          
              
          pub fusion_pool: solana_pubkey::Pubkey,
          
              
          pub position_lock: solana_pubkey::Pubkey,
                /// 
/// Other accounts
/// 

    
              
          pub token2022_program: solana_pubkey::Pubkey,
          
              
          pub system_program: solana_pubkey::Pubkey,
      }

impl LockLpPositionFusion {
  pub fn instruction(&self, args: LockLpPositionFusionInstructionArgs) -> 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: LockLpPositionFusionInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
    let mut accounts = Vec::with_capacity(9+ remaining_accounts.len());
                            accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.authority,
            true
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.tuna_position,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.tuna_position_ata,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.tuna_position_mint,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.fusionamm_program,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.fusion_pool,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.position_lock,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token2022_program,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.system_program,
            false
          ));
                      accounts.extend_from_slice(remaining_accounts);
    let mut data = borsh::to_vec(&LockLpPositionFusionInstructionData::new()).unwrap();
          let mut args = borsh::to_vec(&args).unwrap();
      data.append(&mut args);
    
    solana_instruction::Instruction {
      program_id: crate::TUNA_ID,
      accounts,
      data,
    }
  }
}

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

impl LockLpPositionFusionInstructionData {
  pub fn new() -> Self {
    Self {
                        discriminator: [231, 87, 69, 13, 113, 64, 173, 208],
                                }
  }
}

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

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
 pub struct LockLpPositionFusionInstructionArgs {
                  pub lock_type: PositionLockType,
      }


/// Instruction builder for `LockLpPositionFusion`.
///
/// ### Accounts:
///
                ///   0. `[signer]` authority
                ///   1. `[writable]` tuna_position
                ///   2. `[writable]` tuna_position_ata
                ///   3. `[writable]` tuna_position_mint
          ///   4. `[]` fusionamm_program
                ///   5. `[writable]` fusion_pool
                ///   6. `[writable]` position_lock
          ///   7. `[]` token2022_program
                ///   8. `[optional]` system_program (default to `11111111111111111111111111111111`)
#[derive(Clone, Debug, Default)]
pub struct LockLpPositionFusionBuilder {
            authority: Option<solana_pubkey::Pubkey>,
                tuna_position: Option<solana_pubkey::Pubkey>,
                tuna_position_ata: Option<solana_pubkey::Pubkey>,
                tuna_position_mint: Option<solana_pubkey::Pubkey>,
                fusionamm_program: Option<solana_pubkey::Pubkey>,
                fusion_pool: Option<solana_pubkey::Pubkey>,
                position_lock: Option<solana_pubkey::Pubkey>,
                token2022_program: Option<solana_pubkey::Pubkey>,
                system_program: Option<solana_pubkey::Pubkey>,
                        lock_type: Option<PositionLockType>,
        __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl LockLpPositionFusionBuilder {
  pub fn new() -> Self {
    Self::default()
  }
            #[inline(always)]
    pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
                        self.authority = Some(authority);
                    self
    }
            #[inline(always)]
    pub fn tuna_position(&mut self, tuna_position: solana_pubkey::Pubkey) -> &mut Self {
                        self.tuna_position = Some(tuna_position);
                    self
    }
            #[inline(always)]
    pub fn tuna_position_ata(&mut self, tuna_position_ata: solana_pubkey::Pubkey) -> &mut Self {
                        self.tuna_position_ata = Some(tuna_position_ata);
                    self
    }
            #[inline(always)]
    pub fn tuna_position_mint(&mut self, tuna_position_mint: solana_pubkey::Pubkey) -> &mut Self {
                        self.tuna_position_mint = Some(tuna_position_mint);
                    self
    }
            /// 
/// Fusion accounts
/// 
#[inline(always)]
    pub fn fusionamm_program(&mut self, fusionamm_program: solana_pubkey::Pubkey) -> &mut Self {
                        self.fusionamm_program = Some(fusionamm_program);
                    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 position_lock(&mut self, position_lock: solana_pubkey::Pubkey) -> &mut Self {
                        self.position_lock = Some(position_lock);
                    self
    }
            /// 
/// Other accounts
/// 
#[inline(always)]
    pub fn token2022_program(&mut self, token2022_program: solana_pubkey::Pubkey) -> &mut Self {
                        self.token2022_program = Some(token2022_program);
                    self
    }
            /// `[optional account, default to '11111111111111111111111111111111']`
#[inline(always)]
    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
                        self.system_program = Some(system_program);
                    self
    }
                    #[inline(always)]
      pub fn lock_type(&mut self, lock_type: PositionLockType) -> &mut Self {
        self.lock_type = Some(lock_type);
        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 = LockLpPositionFusion {
                              authority: self.authority.expect("authority is not set"),
                                        tuna_position: self.tuna_position.expect("tuna_position is not set"),
                                        tuna_position_ata: self.tuna_position_ata.expect("tuna_position_ata is not set"),
                                        tuna_position_mint: self.tuna_position_mint.expect("tuna_position_mint is not set"),
                                        fusionamm_program: self.fusionamm_program.expect("fusionamm_program is not set"),
                                        fusion_pool: self.fusion_pool.expect("fusion_pool is not set"),
                                        position_lock: self.position_lock.expect("position_lock is not set"),
                                        token2022_program: self.token2022_program.expect("token2022_program is not set"),
                                        system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
                      };
          let args = LockLpPositionFusionInstructionArgs {
                                                              lock_type: self.lock_type.clone().expect("lock_type is not set"),
                                    };
    
    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
  }
}

  /// `lock_lp_position_fusion` CPI accounts.
  pub struct LockLpPositionFusionCpiAccounts<'a, 'b> {
          
                    
              pub authority: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub tuna_position: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub tuna_position_ata: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub tuna_position_mint: &'b solana_account_info::AccountInfo<'a>,
                        /// 
/// Fusion accounts
/// 

      
                    
              pub fusionamm_program: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub fusion_pool: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub position_lock: &'b solana_account_info::AccountInfo<'a>,
                        /// 
/// Other accounts
/// 

      
                    
              pub token2022_program: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub system_program: &'b solana_account_info::AccountInfo<'a>,
            }

/// `lock_lp_position_fusion` CPI instruction.
pub struct LockLpPositionFusionCpi<'a, 'b> {
  /// The program to invoke.
  pub __program: &'b solana_account_info::AccountInfo<'a>,
      
              
          pub authority: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub tuna_position: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub tuna_position_ata: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub tuna_position_mint: &'b solana_account_info::AccountInfo<'a>,
                /// 
/// Fusion accounts
/// 

    
              
          pub fusionamm_program: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub fusion_pool: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub position_lock: &'b solana_account_info::AccountInfo<'a>,
                /// 
/// Other accounts
/// 

    
              
          pub token2022_program: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub system_program: &'b solana_account_info::AccountInfo<'a>,
            /// The arguments for the instruction.
    pub __args: LockLpPositionFusionInstructionArgs,
  }

impl<'a, 'b> LockLpPositionFusionCpi<'a, 'b> {
  pub fn new(
    program: &'b solana_account_info::AccountInfo<'a>,
          accounts: LockLpPositionFusionCpiAccounts<'a, 'b>,
              args: LockLpPositionFusionInstructionArgs,
      ) -> Self {
    Self {
      __program: program,
              authority: accounts.authority,
              tuna_position: accounts.tuna_position,
              tuna_position_ata: accounts.tuna_position_ata,
              tuna_position_mint: accounts.tuna_position_mint,
              fusionamm_program: accounts.fusionamm_program,
              fusion_pool: accounts.fusion_pool,
              position_lock: accounts.position_lock,
              token2022_program: accounts.token2022_program,
              system_program: accounts.system_program,
                    __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(9+ remaining_accounts.len());
                            accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.authority.key,
            true
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.tuna_position.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.tuna_position_ata.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.tuna_position_mint.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.fusionamm_program.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.fusion_pool.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.position_lock.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token2022_program.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.system_program.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(&LockLpPositionFusionInstructionData::new()).unwrap();
          let mut args = borsh::to_vec(&self.__args).unwrap();
      data.append(&mut args);
    
    let instruction = solana_instruction::Instruction {
      program_id: crate::TUNA_ID,
      accounts,
      data,
    };
    let mut account_infos = Vec::with_capacity(10 + remaining_accounts.len());
    account_infos.push(self.__program.clone());
                  account_infos.push(self.authority.clone());
                        account_infos.push(self.tuna_position.clone());
                        account_infos.push(self.tuna_position_ata.clone());
                        account_infos.push(self.tuna_position_mint.clone());
                        account_infos.push(self.fusionamm_program.clone());
                        account_infos.push(self.fusion_pool.clone());
                        account_infos.push(self.position_lock.clone());
                        account_infos.push(self.token2022_program.clone());
                        account_infos.push(self.system_program.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 `LockLpPositionFusion` via CPI.
///
/// ### Accounts:
///
                ///   0. `[signer]` authority
                ///   1. `[writable]` tuna_position
                ///   2. `[writable]` tuna_position_ata
                ///   3. `[writable]` tuna_position_mint
          ///   4. `[]` fusionamm_program
                ///   5. `[writable]` fusion_pool
                ///   6. `[writable]` position_lock
          ///   7. `[]` token2022_program
          ///   8. `[]` system_program
#[derive(Clone, Debug)]
pub struct LockLpPositionFusionCpiBuilder<'a, 'b> {
  instruction: Box<LockLpPositionFusionCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> LockLpPositionFusionCpiBuilder<'a, 'b> {
  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
    let instruction = Box::new(LockLpPositionFusionCpiBuilderInstruction {
      __program: program,
              authority: None,
              tuna_position: None,
              tuna_position_ata: None,
              tuna_position_mint: None,
              fusionamm_program: None,
              fusion_pool: None,
              position_lock: None,
              token2022_program: None,
              system_program: None,
                                            lock_type: None,
                    __remaining_accounts: Vec::new(),
    });
    Self { instruction }
  }
      #[inline(always)]
    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.authority = Some(authority);
                    self
    }
      #[inline(always)]
    pub fn tuna_position(&mut self, tuna_position: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position = Some(tuna_position);
                    self
    }
      #[inline(always)]
    pub fn tuna_position_ata(&mut self, tuna_position_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position_ata = Some(tuna_position_ata);
                    self
    }
      #[inline(always)]
    pub fn tuna_position_mint(&mut self, tuna_position_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position_mint = Some(tuna_position_mint);
                    self
    }
      /// 
/// Fusion accounts
/// 
#[inline(always)]
    pub fn fusionamm_program(&mut self, fusionamm_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.fusionamm_program = Some(fusionamm_program);
                    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 position_lock(&mut self, position_lock: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.position_lock = Some(position_lock);
                    self
    }
      /// 
/// Other accounts
/// 
#[inline(always)]
    pub fn token2022_program(&mut self, token2022_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.token2022_program = Some(token2022_program);
                    self
    }
      #[inline(always)]
    pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.system_program = Some(system_program);
                    self
    }
                    #[inline(always)]
      pub fn lock_type(&mut self, lock_type: PositionLockType) -> &mut Self {
        self.instruction.lock_type = Some(lock_type);
        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 = LockLpPositionFusionInstructionArgs {
                                                              lock_type: self.instruction.lock_type.clone().expect("lock_type is not set"),
                                    };
        let instruction = LockLpPositionFusionCpi {
        __program: self.instruction.__program,
                  
          authority: self.instruction.authority.expect("authority is not set"),
                  
          tuna_position: self.instruction.tuna_position.expect("tuna_position is not set"),
                  
          tuna_position_ata: self.instruction.tuna_position_ata.expect("tuna_position_ata is not set"),
                  
          tuna_position_mint: self.instruction.tuna_position_mint.expect("tuna_position_mint is not set"),
                  
          fusionamm_program: self.instruction.fusionamm_program.expect("fusionamm_program is not set"),
                  
          fusion_pool: self.instruction.fusion_pool.expect("fusion_pool is not set"),
                  
          position_lock: self.instruction.position_lock.expect("position_lock is not set"),
                  
          token2022_program: self.instruction.token2022_program.expect("token2022_program is not set"),
                  
          system_program: self.instruction.system_program.expect("system_program is not set"),
                          __args: args,
            };
    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
  }
}

#[derive(Clone, Debug)]
struct LockLpPositionFusionCpiBuilderInstruction<'a, 'b> {
  __program: &'b solana_account_info::AccountInfo<'a>,
            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
                tuna_position: Option<&'b solana_account_info::AccountInfo<'a>>,
                tuna_position_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
                tuna_position_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
                fusionamm_program: Option<&'b solana_account_info::AccountInfo<'a>>,
                fusion_pool: Option<&'b solana_account_info::AccountInfo<'a>>,
                position_lock: Option<&'b solana_account_info::AccountInfo<'a>>,
                token2022_program: Option<&'b solana_account_info::AccountInfo<'a>>,
                system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
                        lock_type: Option<PositionLockType>,
        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}

