//! 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::GraduationMethod;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;

pub const CREATE_PRESALE_DISCRIMINATOR: u8 = 42;

/// Accounts.
#[derive(Debug)]
pub struct CreatePresale {
    /// The creator of the token
    pub creator: solana_pubkey::Pubkey,
    /// The bonding curve account
    pub bonding_curve: solana_pubkey::Pubkey,
    /// The token mint account
    pub base_mint: solana_pubkey::Pubkey,
    /// The quote token mint account
    pub quote_mint: solana_pubkey::Pubkey,
    /// The quote token vault
    pub quote_vault: solana_pubkey::Pubkey,
    /// The base token mint config account
    pub mint_config: solana_pubkey::Pubkey,
    /// The metadata account
    pub metadata: solana_pubkey::Pubkey,
    /// System program
    pub system_program: solana_pubkey::Pubkey,
    /// The token program for the new token
    pub base_token_program: solana_pubkey::Pubkey,
    /// The token program for the quote token
    pub quote_token_program: solana_pubkey::Pubkey,
    /// The associated token account program
    pub ata_program: solana_pubkey::Pubkey,
    /// The metaplex metadata program
    pub metaplex_program: solana_pubkey::Pubkey,
}

impl CreatePresale {
    pub fn instruction(
        &self,
        args: CreatePresaleInstructionArgs,
    ) -> 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: CreatePresaleInstructionArgs,
        remaining_accounts: &[solana_instruction::AccountMeta],
    ) -> solana_instruction::Instruction {
        let mut accounts = Vec::with_capacity(12 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new(self.creator, true));
        accounts.push(solana_instruction::AccountMeta::new(
            self.bonding_curve,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(self.base_mint, true));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.quote_mint,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.quote_vault,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.mint_config,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(self.metadata, false));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.system_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.base_token_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.quote_token_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.ata_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.metaplex_program,
            false,
        ));
        accounts.extend_from_slice(remaining_accounts);
        let mut data = borsh::to_vec(&CreatePresaleInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&args).unwrap();
        data.append(&mut args);

        solana_instruction::Instruction {
            program_id: crate::WAVEBREAK_ID,
            accounts,
            data,
        }
    }
}

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

impl CreatePresaleInstructionData {
    pub fn new() -> Self {
        Self { discriminator: 42 }
    }
}

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

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreatePresaleInstructionArgs {
    pub name: String,
    pub symbol: String,
    pub uri: String,
    pub token_price: Option<u128>,
    pub graduation_target: Option<u64>,
    pub graduation_methods: Option<[GraduationMethod; 8]>,
    pub launch_slot: Option<u64>,
    pub graduation_slot: Option<u64>,
    pub min_reserve_bps: Option<u16>,
    pub base_allocation_bps: Option<u16>,
}

/// Instruction builder for `CreatePresale`.
///
/// ### Accounts:
///
///   0. `[writable, signer]` creator
///   1. `[writable]` bonding_curve
///   2. `[writable, signer]` base_mint
///   3. `[]` quote_mint
///   4. `[writable]` quote_vault
///   5. `[]` mint_config
///   6. `[writable]` metadata
///   7. `[optional]` system_program (default to `11111111111111111111111111111111`)
///   8. `[]` base_token_program
///   9. `[]` quote_token_program
///   10. `[optional]` ata_program (default to `ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL`)
///   11. `[]` metaplex_program
#[derive(Clone, Debug, Default)]
pub struct CreatePresaleBuilder {
    creator: Option<solana_pubkey::Pubkey>,
    bonding_curve: Option<solana_pubkey::Pubkey>,
    base_mint: Option<solana_pubkey::Pubkey>,
    quote_mint: Option<solana_pubkey::Pubkey>,
    quote_vault: Option<solana_pubkey::Pubkey>,
    mint_config: Option<solana_pubkey::Pubkey>,
    metadata: Option<solana_pubkey::Pubkey>,
    system_program: Option<solana_pubkey::Pubkey>,
    base_token_program: Option<solana_pubkey::Pubkey>,
    quote_token_program: Option<solana_pubkey::Pubkey>,
    ata_program: Option<solana_pubkey::Pubkey>,
    metaplex_program: Option<solana_pubkey::Pubkey>,
    name: Option<String>,
    symbol: Option<String>,
    uri: Option<String>,
    token_price: Option<u128>,
    graduation_target: Option<u64>,
    graduation_methods: Option<[GraduationMethod; 8]>,
    launch_slot: Option<u64>,
    graduation_slot: Option<u64>,
    min_reserve_bps: Option<u16>,
    base_allocation_bps: Option<u16>,
    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl CreatePresaleBuilder {
    pub fn new() -> Self {
        Self::default()
    }
    /// The creator of the token
    #[inline(always)]
    pub fn creator(&mut self, creator: solana_pubkey::Pubkey) -> &mut Self {
        self.creator = Some(creator);
        self
    }
    /// The bonding curve account
    #[inline(always)]
    pub fn bonding_curve(&mut self, bonding_curve: solana_pubkey::Pubkey) -> &mut Self {
        self.bonding_curve = Some(bonding_curve);
        self
    }
    /// The token mint account
    #[inline(always)]
    pub fn base_mint(&mut self, base_mint: solana_pubkey::Pubkey) -> &mut Self {
        self.base_mint = Some(base_mint);
        self
    }
    /// The quote token mint account
    #[inline(always)]
    pub fn quote_mint(&mut self, quote_mint: solana_pubkey::Pubkey) -> &mut Self {
        self.quote_mint = Some(quote_mint);
        self
    }
    /// The quote token vault
    #[inline(always)]
    pub fn quote_vault(&mut self, quote_vault: solana_pubkey::Pubkey) -> &mut Self {
        self.quote_vault = Some(quote_vault);
        self
    }
    /// The base token mint config account
    #[inline(always)]
    pub fn mint_config(&mut self, mint_config: solana_pubkey::Pubkey) -> &mut Self {
        self.mint_config = Some(mint_config);
        self
    }
    /// The metadata account
    #[inline(always)]
    pub fn metadata(&mut self, metadata: solana_pubkey::Pubkey) -> &mut Self {
        self.metadata = Some(metadata);
        self
    }
    /// `[optional account, default to '11111111111111111111111111111111']`
    /// System program
    #[inline(always)]
    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
        self.system_program = Some(system_program);
        self
    }
    /// The token program for the new token
    #[inline(always)]
    pub fn base_token_program(&mut self, base_token_program: solana_pubkey::Pubkey) -> &mut Self {
        self.base_token_program = Some(base_token_program);
        self
    }
    /// The token program for the quote token
    #[inline(always)]
    pub fn quote_token_program(&mut self, quote_token_program: solana_pubkey::Pubkey) -> &mut Self {
        self.quote_token_program = Some(quote_token_program);
        self
    }
    /// `[optional account, default to 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL']`
    /// The associated token account program
    #[inline(always)]
    pub fn ata_program(&mut self, ata_program: solana_pubkey::Pubkey) -> &mut Self {
        self.ata_program = Some(ata_program);
        self
    }
    /// The metaplex metadata program
    #[inline(always)]
    pub fn metaplex_program(&mut self, metaplex_program: solana_pubkey::Pubkey) -> &mut Self {
        self.metaplex_program = Some(metaplex_program);
        self
    }
    #[inline(always)]
    pub fn name(&mut self, name: String) -> &mut Self {
        self.name = Some(name);
        self
    }
    #[inline(always)]
    pub fn symbol(&mut self, symbol: String) -> &mut Self {
        self.symbol = Some(symbol);
        self
    }
    #[inline(always)]
    pub fn uri(&mut self, uri: String) -> &mut Self {
        self.uri = Some(uri);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn token_price(&mut self, token_price: u128) -> &mut Self {
        self.token_price = Some(token_price);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn graduation_target(&mut self, graduation_target: u64) -> &mut Self {
        self.graduation_target = Some(graduation_target);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn graduation_methods(&mut self, graduation_methods: [GraduationMethod; 8]) -> &mut Self {
        self.graduation_methods = Some(graduation_methods);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn launch_slot(&mut self, launch_slot: u64) -> &mut Self {
        self.launch_slot = Some(launch_slot);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn graduation_slot(&mut self, graduation_slot: u64) -> &mut Self {
        self.graduation_slot = Some(graduation_slot);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn min_reserve_bps(&mut self, min_reserve_bps: u16) -> &mut Self {
        self.min_reserve_bps = Some(min_reserve_bps);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn base_allocation_bps(&mut self, base_allocation_bps: u16) -> &mut Self {
        self.base_allocation_bps = Some(base_allocation_bps);
        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 = CreatePresale {
            creator: self.creator.expect("creator is not set"),
            bonding_curve: self.bonding_curve.expect("bonding_curve is not set"),
            base_mint: self.base_mint.expect("base_mint is not set"),
            quote_mint: self.quote_mint.expect("quote_mint is not set"),
            quote_vault: self.quote_vault.expect("quote_vault is not set"),
            mint_config: self.mint_config.expect("mint_config is not set"),
            metadata: self.metadata.expect("metadata is not set"),
            system_program: self
                .system_program
                .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
            base_token_program: self
                .base_token_program
                .expect("base_token_program is not set"),
            quote_token_program: self
                .quote_token_program
                .expect("quote_token_program is not set"),
            ata_program: self.ata_program.unwrap_or(solana_pubkey::pubkey!(
                "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
            )),
            metaplex_program: self.metaplex_program.expect("metaplex_program is not set"),
        };
        let args = CreatePresaleInstructionArgs {
            name: self.name.clone().expect("name is not set"),
            symbol: self.symbol.clone().expect("symbol is not set"),
            uri: self.uri.clone().expect("uri is not set"),
            token_price: self.token_price.clone(),
            graduation_target: self.graduation_target.clone(),
            graduation_methods: self.graduation_methods.clone(),
            launch_slot: self.launch_slot.clone(),
            graduation_slot: self.graduation_slot.clone(),
            min_reserve_bps: self.min_reserve_bps.clone(),
            base_allocation_bps: self.base_allocation_bps.clone(),
        };

        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
    }
}

/// `create_presale` CPI accounts.
pub struct CreatePresaleCpiAccounts<'a, 'b> {
    /// The creator of the token
    pub creator: &'b solana_account_info::AccountInfo<'a>,
    /// The bonding curve account
    pub bonding_curve: &'b solana_account_info::AccountInfo<'a>,
    /// The token mint account
    pub base_mint: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token mint account
    pub quote_mint: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token vault
    pub quote_vault: &'b solana_account_info::AccountInfo<'a>,
    /// The base token mint config account
    pub mint_config: &'b solana_account_info::AccountInfo<'a>,
    /// The metadata account
    pub metadata: &'b solana_account_info::AccountInfo<'a>,
    /// System program
    pub system_program: &'b solana_account_info::AccountInfo<'a>,
    /// The token program for the new token
    pub base_token_program: &'b solana_account_info::AccountInfo<'a>,
    /// The token program for the quote token
    pub quote_token_program: &'b solana_account_info::AccountInfo<'a>,
    /// The associated token account program
    pub ata_program: &'b solana_account_info::AccountInfo<'a>,
    /// The metaplex metadata program
    pub metaplex_program: &'b solana_account_info::AccountInfo<'a>,
}

/// `create_presale` CPI instruction.
pub struct CreatePresaleCpi<'a, 'b> {
    /// The program to invoke.
    pub __program: &'b solana_account_info::AccountInfo<'a>,
    /// The creator of the token
    pub creator: &'b solana_account_info::AccountInfo<'a>,
    /// The bonding curve account
    pub bonding_curve: &'b solana_account_info::AccountInfo<'a>,
    /// The token mint account
    pub base_mint: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token mint account
    pub quote_mint: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token vault
    pub quote_vault: &'b solana_account_info::AccountInfo<'a>,
    /// The base token mint config account
    pub mint_config: &'b solana_account_info::AccountInfo<'a>,
    /// The metadata account
    pub metadata: &'b solana_account_info::AccountInfo<'a>,
    /// System program
    pub system_program: &'b solana_account_info::AccountInfo<'a>,
    /// The token program for the new token
    pub base_token_program: &'b solana_account_info::AccountInfo<'a>,
    /// The token program for the quote token
    pub quote_token_program: &'b solana_account_info::AccountInfo<'a>,
    /// The associated token account program
    pub ata_program: &'b solana_account_info::AccountInfo<'a>,
    /// The metaplex metadata program
    pub metaplex_program: &'b solana_account_info::AccountInfo<'a>,
    /// The arguments for the instruction.
    pub __args: CreatePresaleInstructionArgs,
}

impl<'a, 'b> CreatePresaleCpi<'a, 'b> {
    pub fn new(
        program: &'b solana_account_info::AccountInfo<'a>,
        accounts: CreatePresaleCpiAccounts<'a, 'b>,
        args: CreatePresaleInstructionArgs,
    ) -> Self {
        Self {
            __program: program,
            creator: accounts.creator,
            bonding_curve: accounts.bonding_curve,
            base_mint: accounts.base_mint,
            quote_mint: accounts.quote_mint,
            quote_vault: accounts.quote_vault,
            mint_config: accounts.mint_config,
            metadata: accounts.metadata,
            system_program: accounts.system_program,
            base_token_program: accounts.base_token_program,
            quote_token_program: accounts.quote_token_program,
            ata_program: accounts.ata_program,
            metaplex_program: accounts.metaplex_program,
            __args: args,
        }
    }
    #[inline(always)]
    pub fn invoke(&self) -> solana_program_entrypoint::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_entrypoint::ProgramResult {
        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
    }
    #[inline(always)]
    pub fn invoke_signed(
        &self,
        signers_seeds: &[&[&[u8]]],
    ) -> solana_program_entrypoint::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_entrypoint::ProgramResult {
        let mut accounts = Vec::with_capacity(12 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new(
            *self.creator.key,
            true,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.bonding_curve.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.base_mint.key,
            true,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.quote_mint.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.quote_vault.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.mint_config.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.metadata.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.system_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.base_token_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.quote_token_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.ata_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.metaplex_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(&CreatePresaleInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&self.__args).unwrap();
        data.append(&mut args);

        let instruction = solana_instruction::Instruction {
            program_id: crate::WAVEBREAK_ID,
            accounts,
            data,
        };
        let mut account_infos = Vec::with_capacity(13 + remaining_accounts.len());
        account_infos.push(self.__program.clone());
        account_infos.push(self.creator.clone());
        account_infos.push(self.bonding_curve.clone());
        account_infos.push(self.base_mint.clone());
        account_infos.push(self.quote_mint.clone());
        account_infos.push(self.quote_vault.clone());
        account_infos.push(self.mint_config.clone());
        account_infos.push(self.metadata.clone());
        account_infos.push(self.system_program.clone());
        account_infos.push(self.base_token_program.clone());
        account_infos.push(self.quote_token_program.clone());
        account_infos.push(self.ata_program.clone());
        account_infos.push(self.metaplex_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 `CreatePresale` via CPI.
///
/// ### Accounts:
///
///   0. `[writable, signer]` creator
///   1. `[writable]` bonding_curve
///   2. `[writable, signer]` base_mint
///   3. `[]` quote_mint
///   4. `[writable]` quote_vault
///   5. `[]` mint_config
///   6. `[writable]` metadata
///   7. `[]` system_program
///   8. `[]` base_token_program
///   9. `[]` quote_token_program
///   10. `[]` ata_program
///   11. `[]` metaplex_program
#[derive(Clone, Debug)]
pub struct CreatePresaleCpiBuilder<'a, 'b> {
    instruction: Box<CreatePresaleCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> CreatePresaleCpiBuilder<'a, 'b> {
    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
        let instruction = Box::new(CreatePresaleCpiBuilderInstruction {
            __program: program,
            creator: None,
            bonding_curve: None,
            base_mint: None,
            quote_mint: None,
            quote_vault: None,
            mint_config: None,
            metadata: None,
            system_program: None,
            base_token_program: None,
            quote_token_program: None,
            ata_program: None,
            metaplex_program: None,
            name: None,
            symbol: None,
            uri: None,
            token_price: None,
            graduation_target: None,
            graduation_methods: None,
            launch_slot: None,
            graduation_slot: None,
            min_reserve_bps: None,
            base_allocation_bps: None,
            __remaining_accounts: Vec::new(),
        });
        Self { instruction }
    }
    /// The creator of the token
    #[inline(always)]
    pub fn creator(&mut self, creator: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.creator = Some(creator);
        self
    }
    /// The bonding curve account
    #[inline(always)]
    pub fn bonding_curve(
        &mut self,
        bonding_curve: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.bonding_curve = Some(bonding_curve);
        self
    }
    /// The token mint account
    #[inline(always)]
    pub fn base_mint(&mut self, base_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.base_mint = Some(base_mint);
        self
    }
    /// The quote token mint account
    #[inline(always)]
    pub fn quote_mint(
        &mut self,
        quote_mint: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.quote_mint = Some(quote_mint);
        self
    }
    /// The quote token vault
    #[inline(always)]
    pub fn quote_vault(
        &mut self,
        quote_vault: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.quote_vault = Some(quote_vault);
        self
    }
    /// The base token mint config account
    #[inline(always)]
    pub fn mint_config(
        &mut self,
        mint_config: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.mint_config = Some(mint_config);
        self
    }
    /// The metadata account
    #[inline(always)]
    pub fn metadata(&mut self, metadata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.metadata = Some(metadata);
        self
    }
    /// System program
    #[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
    }
    /// The token program for the new token
    #[inline(always)]
    pub fn base_token_program(
        &mut self,
        base_token_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.base_token_program = Some(base_token_program);
        self
    }
    /// The token program for the quote token
    #[inline(always)]
    pub fn quote_token_program(
        &mut self,
        quote_token_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.quote_token_program = Some(quote_token_program);
        self
    }
    /// The associated token account program
    #[inline(always)]
    pub fn ata_program(
        &mut self,
        ata_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.ata_program = Some(ata_program);
        self
    }
    /// The metaplex metadata program
    #[inline(always)]
    pub fn metaplex_program(
        &mut self,
        metaplex_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.metaplex_program = Some(metaplex_program);
        self
    }
    #[inline(always)]
    pub fn name(&mut self, name: String) -> &mut Self {
        self.instruction.name = Some(name);
        self
    }
    #[inline(always)]
    pub fn symbol(&mut self, symbol: String) -> &mut Self {
        self.instruction.symbol = Some(symbol);
        self
    }
    #[inline(always)]
    pub fn uri(&mut self, uri: String) -> &mut Self {
        self.instruction.uri = Some(uri);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn token_price(&mut self, token_price: u128) -> &mut Self {
        self.instruction.token_price = Some(token_price);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn graduation_target(&mut self, graduation_target: u64) -> &mut Self {
        self.instruction.graduation_target = Some(graduation_target);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn graduation_methods(&mut self, graduation_methods: [GraduationMethod; 8]) -> &mut Self {
        self.instruction.graduation_methods = Some(graduation_methods);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn launch_slot(&mut self, launch_slot: u64) -> &mut Self {
        self.instruction.launch_slot = Some(launch_slot);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn graduation_slot(&mut self, graduation_slot: u64) -> &mut Self {
        self.instruction.graduation_slot = Some(graduation_slot);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn min_reserve_bps(&mut self, min_reserve_bps: u16) -> &mut Self {
        self.instruction.min_reserve_bps = Some(min_reserve_bps);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn base_allocation_bps(&mut self, base_allocation_bps: u16) -> &mut Self {
        self.instruction.base_allocation_bps = Some(base_allocation_bps);
        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_entrypoint::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_entrypoint::ProgramResult {
        let args = CreatePresaleInstructionArgs {
            name: self.instruction.name.clone().expect("name is not set"),
            symbol: self.instruction.symbol.clone().expect("symbol is not set"),
            uri: self.instruction.uri.clone().expect("uri is not set"),
            token_price: self.instruction.token_price.clone(),
            graduation_target: self.instruction.graduation_target.clone(),
            graduation_methods: self.instruction.graduation_methods.clone(),
            launch_slot: self.instruction.launch_slot.clone(),
            graduation_slot: self.instruction.graduation_slot.clone(),
            min_reserve_bps: self.instruction.min_reserve_bps.clone(),
            base_allocation_bps: self.instruction.base_allocation_bps.clone(),
        };
        let instruction = CreatePresaleCpi {
            __program: self.instruction.__program,

            creator: self.instruction.creator.expect("creator is not set"),

            bonding_curve: self
                .instruction
                .bonding_curve
                .expect("bonding_curve is not set"),

            base_mint: self.instruction.base_mint.expect("base_mint is not set"),

            quote_mint: self.instruction.quote_mint.expect("quote_mint is not set"),

            quote_vault: self
                .instruction
                .quote_vault
                .expect("quote_vault is not set"),

            mint_config: self
                .instruction
                .mint_config
                .expect("mint_config is not set"),

            metadata: self.instruction.metadata.expect("metadata is not set"),

            system_program: self
                .instruction
                .system_program
                .expect("system_program is not set"),

            base_token_program: self
                .instruction
                .base_token_program
                .expect("base_token_program is not set"),

            quote_token_program: self
                .instruction
                .quote_token_program
                .expect("quote_token_program is not set"),

            ata_program: self
                .instruction
                .ata_program
                .expect("ata_program is not set"),

            metaplex_program: self
                .instruction
                .metaplex_program
                .expect("metaplex_program is not set"),
            __args: args,
        };
        instruction.invoke_signed_with_remaining_accounts(
            signers_seeds,
            &self.instruction.__remaining_accounts,
        )
    }
}

#[derive(Clone, Debug)]
struct CreatePresaleCpiBuilderInstruction<'a, 'b> {
    __program: &'b solana_account_info::AccountInfo<'a>,
    creator: Option<&'b solana_account_info::AccountInfo<'a>>,
    bonding_curve: Option<&'b solana_account_info::AccountInfo<'a>>,
    base_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
    quote_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
    quote_vault: Option<&'b solana_account_info::AccountInfo<'a>>,
    mint_config: Option<&'b solana_account_info::AccountInfo<'a>>,
    metadata: Option<&'b solana_account_info::AccountInfo<'a>>,
    system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    base_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    quote_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    ata_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    metaplex_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    name: Option<String>,
    symbol: Option<String>,
    uri: Option<String>,
    token_price: Option<u128>,
    graduation_target: Option<u64>,
    graduation_methods: Option<[GraduationMethod; 8]>,
    launch_slot: Option<u64>,
    graduation_slot: Option<u64>,
    min_reserve_bps: Option<u16>,
    base_allocation_bps: Option<u16>,
    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}
