//! 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 CLOSE_TUNA_SPOT_POSITION_DISCRIMINATOR: [u8; 8] = [4, 189, 171, 84, 110, 220, 10, 8];

/// Accounts.
#[derive(Debug)]
pub struct CloseTunaSpotPosition {
            /// 
/// TUNA accounts
/// 

    
              
          pub authority: solana_pubkey::Pubkey,
          
              
          pub mint_a: solana_pubkey::Pubkey,
          
              
          pub mint_b: solana_pubkey::Pubkey,
          
              
          pub token_program_a: solana_pubkey::Pubkey,
          
              
          pub token_program_b: solana_pubkey::Pubkey,
          
              
          pub market: solana_pubkey::Pubkey,
          
              
          pub tuna_position: solana_pubkey::Pubkey,
          
              
          pub tuna_position_ata_a: solana_pubkey::Pubkey,
          
              
          pub tuna_position_ata_b: solana_pubkey::Pubkey,
      }

impl CloseTunaSpotPosition {
  pub fn instruction(&self) -> solana_instruction::Instruction {
    self.instruction_with_remaining_accounts(&[])
  }
  #[allow(clippy::arithmetic_side_effects)]
  #[allow(clippy::vec_init_then_push)]
  pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
    let mut accounts = Vec::with_capacity(9+ remaining_accounts.len());
                            accounts.push(solana_instruction::AccountMeta::new(
            self.authority,
            true
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.mint_a,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.mint_b,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_program_a,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_program_b,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.market,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.tuna_position,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.tuna_position_ata_a,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.tuna_position_ata_b,
            false
          ));
                      accounts.extend_from_slice(remaining_accounts);
    let data = borsh::to_vec(&CloseTunaSpotPositionInstructionData::new()).unwrap();
    
    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 CloseTunaSpotPositionInstructionData {
            discriminator: [u8; 8],
      }

impl CloseTunaSpotPositionInstructionData {
  pub fn new() -> Self {
    Self {
                        discriminator: [4, 189, 171, 84, 110, 220, 10, 8],
                  }
  }
}

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



/// Instruction builder for `CloseTunaSpotPosition`.
///
/// ### Accounts:
///
                      ///   0. `[writable, signer]` authority
          ///   1. `[]` mint_a
          ///   2. `[]` mint_b
          ///   3. `[]` token_program_a
          ///   4. `[]` token_program_b
                ///   5. `[writable]` market
                ///   6. `[writable]` tuna_position
                ///   7. `[writable]` tuna_position_ata_a
                ///   8. `[writable]` tuna_position_ata_b
#[derive(Clone, Debug, Default)]
pub struct CloseTunaSpotPositionBuilder {
            authority: Option<solana_pubkey::Pubkey>,
                mint_a: Option<solana_pubkey::Pubkey>,
                mint_b: Option<solana_pubkey::Pubkey>,
                token_program_a: Option<solana_pubkey::Pubkey>,
                token_program_b: Option<solana_pubkey::Pubkey>,
                market: Option<solana_pubkey::Pubkey>,
                tuna_position: Option<solana_pubkey::Pubkey>,
                tuna_position_ata_a: Option<solana_pubkey::Pubkey>,
                tuna_position_ata_b: Option<solana_pubkey::Pubkey>,
                __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl CloseTunaSpotPositionBuilder {
  pub fn new() -> Self {
    Self::default()
  }
            /// 
/// TUNA accounts
/// 
#[inline(always)]
    pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
                        self.authority = Some(authority);
                    self
    }
            #[inline(always)]
    pub fn mint_a(&mut self, mint_a: solana_pubkey::Pubkey) -> &mut Self {
                        self.mint_a = Some(mint_a);
                    self
    }
            #[inline(always)]
    pub fn mint_b(&mut self, mint_b: solana_pubkey::Pubkey) -> &mut Self {
                        self.mint_b = Some(mint_b);
                    self
    }
            #[inline(always)]
    pub fn token_program_a(&mut self, token_program_a: solana_pubkey::Pubkey) -> &mut Self {
                        self.token_program_a = Some(token_program_a);
                    self
    }
            #[inline(always)]
    pub fn token_program_b(&mut self, token_program_b: solana_pubkey::Pubkey) -> &mut Self {
                        self.token_program_b = Some(token_program_b);
                    self
    }
            #[inline(always)]
    pub fn market(&mut self, market: solana_pubkey::Pubkey) -> &mut Self {
                        self.market = Some(market);
                    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_a(&mut self, tuna_position_ata_a: solana_pubkey::Pubkey) -> &mut Self {
                        self.tuna_position_ata_a = Some(tuna_position_ata_a);
                    self
    }
            #[inline(always)]
    pub fn tuna_position_ata_b(&mut self, tuna_position_ata_b: solana_pubkey::Pubkey) -> &mut Self {
                        self.tuna_position_ata_b = Some(tuna_position_ata_b);
                    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 = CloseTunaSpotPosition {
                              authority: self.authority.expect("authority is not set"),
                                        mint_a: self.mint_a.expect("mint_a is not set"),
                                        mint_b: self.mint_b.expect("mint_b is not set"),
                                        token_program_a: self.token_program_a.expect("token_program_a is not set"),
                                        token_program_b: self.token_program_b.expect("token_program_b is not set"),
                                        market: self.market.expect("market is not set"),
                                        tuna_position: self.tuna_position.expect("tuna_position is not set"),
                                        tuna_position_ata_a: self.tuna_position_ata_a.expect("tuna_position_ata_a is not set"),
                                        tuna_position_ata_b: self.tuna_position_ata_b.expect("tuna_position_ata_b is not set"),
                      };
    
    accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
  }
}

  /// `close_tuna_spot_position` CPI accounts.
  pub struct CloseTunaSpotPositionCpiAccounts<'a, 'b> {
                  /// 
/// TUNA accounts
/// 

      
                    
              pub authority: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub mint_a: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub mint_b: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub token_program_a: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub token_program_b: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub market: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub tuna_position: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub tuna_position_ata_a: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub tuna_position_ata_b: &'b solana_account_info::AccountInfo<'a>,
            }

/// `close_tuna_spot_position` CPI instruction.
pub struct CloseTunaSpotPositionCpi<'a, 'b> {
  /// The program to invoke.
  pub __program: &'b solana_account_info::AccountInfo<'a>,
            /// 
/// TUNA accounts
/// 

    
              
          pub authority: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub mint_a: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub mint_b: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub token_program_a: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub token_program_b: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub market: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub tuna_position: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub tuna_position_ata_a: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub tuna_position_ata_b: &'b solana_account_info::AccountInfo<'a>,
        }

impl<'a, 'b> CloseTunaSpotPositionCpi<'a, 'b> {
  pub fn new(
    program: &'b solana_account_info::AccountInfo<'a>,
          accounts: CloseTunaSpotPositionCpiAccounts<'a, 'b>,
          ) -> Self {
    Self {
      __program: program,
              authority: accounts.authority,
              mint_a: accounts.mint_a,
              mint_b: accounts.mint_b,
              token_program_a: accounts.token_program_a,
              token_program_b: accounts.token_program_b,
              market: accounts.market,
              tuna_position: accounts.tuna_position,
              tuna_position_ata_a: accounts.tuna_position_ata_a,
              tuna_position_ata_b: accounts.tuna_position_ata_b,
                }
  }
  #[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(
            *self.authority.key,
            true
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.mint_a.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.mint_b.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_program_a.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_program_b.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.market.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.tuna_position.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.tuna_position_ata_a.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.tuna_position_ata_b.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 data = borsh::to_vec(&CloseTunaSpotPositionInstructionData::new()).unwrap();
    
    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.mint_a.clone());
                        account_infos.push(self.mint_b.clone());
                        account_infos.push(self.token_program_a.clone());
                        account_infos.push(self.token_program_b.clone());
                        account_infos.push(self.market.clone());
                        account_infos.push(self.tuna_position.clone());
                        account_infos.push(self.tuna_position_ata_a.clone());
                        account_infos.push(self.tuna_position_ata_b.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 `CloseTunaSpotPosition` via CPI.
///
/// ### Accounts:
///
                      ///   0. `[writable, signer]` authority
          ///   1. `[]` mint_a
          ///   2. `[]` mint_b
          ///   3. `[]` token_program_a
          ///   4. `[]` token_program_b
                ///   5. `[writable]` market
                ///   6. `[writable]` tuna_position
                ///   7. `[writable]` tuna_position_ata_a
                ///   8. `[writable]` tuna_position_ata_b
#[derive(Clone, Debug)]
pub struct CloseTunaSpotPositionCpiBuilder<'a, 'b> {
  instruction: Box<CloseTunaSpotPositionCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> CloseTunaSpotPositionCpiBuilder<'a, 'b> {
  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
    let instruction = Box::new(CloseTunaSpotPositionCpiBuilderInstruction {
      __program: program,
              authority: None,
              mint_a: None,
              mint_b: None,
              token_program_a: None,
              token_program_b: None,
              market: None,
              tuna_position: None,
              tuna_position_ata_a: None,
              tuna_position_ata_b: None,
                                __remaining_accounts: Vec::new(),
    });
    Self { instruction }
  }
      /// 
/// TUNA accounts
/// 
#[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 mint_a(&mut self, mint_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.mint_a = Some(mint_a);
                    self
    }
      #[inline(always)]
    pub fn mint_b(&mut self, mint_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.mint_b = Some(mint_b);
                    self
    }
      #[inline(always)]
    pub fn token_program_a(&mut self, token_program_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.token_program_a = Some(token_program_a);
                    self
    }
      #[inline(always)]
    pub fn token_program_b(&mut self, token_program_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.token_program_b = Some(token_program_b);
                    self
    }
      #[inline(always)]
    pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.market = Some(market);
                    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_a(&mut self, tuna_position_ata_a: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position_ata_a = Some(tuna_position_ata_a);
                    self
    }
      #[inline(always)]
    pub fn tuna_position_ata_b(&mut self, tuna_position_ata_b: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position_ata_b = Some(tuna_position_ata_b);
                    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 instruction = CloseTunaSpotPositionCpi {
        __program: self.instruction.__program,
                  
          authority: self.instruction.authority.expect("authority is not set"),
                  
          mint_a: self.instruction.mint_a.expect("mint_a is not set"),
                  
          mint_b: self.instruction.mint_b.expect("mint_b is not set"),
                  
          token_program_a: self.instruction.token_program_a.expect("token_program_a is not set"),
                  
          token_program_b: self.instruction.token_program_b.expect("token_program_b is not set"),
                  
          market: self.instruction.market.expect("market is not set"),
                  
          tuna_position: self.instruction.tuna_position.expect("tuna_position is not set"),
                  
          tuna_position_ata_a: self.instruction.tuna_position_ata_a.expect("tuna_position_ata_a is not set"),
                  
          tuna_position_ata_b: self.instruction.tuna_position_ata_b.expect("tuna_position_ata_b is not set"),
                    };
    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
  }
}

#[derive(Clone, Debug)]
struct CloseTunaSpotPositionCpiBuilderInstruction<'a, 'b> {
  __program: &'b solana_account_info::AccountInfo<'a>,
            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
                mint_a: Option<&'b solana_account_info::AccountInfo<'a>>,
                mint_b: Option<&'b solana_account_info::AccountInfo<'a>>,
                token_program_a: Option<&'b solana_account_info::AccountInfo<'a>>,
                token_program_b: Option<&'b solana_account_info::AccountInfo<'a>>,
                market: Option<&'b solana_account_info::AccountInfo<'a>>,
                tuna_position: Option<&'b solana_account_info::AccountInfo<'a>>,
                tuna_position_ata_a: Option<&'b solana_account_info::AccountInfo<'a>>,
                tuna_position_ata_b: Option<&'b solana_account_info::AccountInfo<'a>>,
                /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}

