//! This code was AUTOGENERATED using the Codama library.
pub mod claim_cashback_pumpfun_row;
pub mod claim_cashback_pumpswap_row;
pub mod claim_row;
pub mod cpi_event_row;
pub mod create_token_account_row;
pub mod create_token_account_with_seed_row;
pub mod proxy_swap_row;
pub mod swap_row;
pub mod swap_tob_v3_enhanced_row;
pub mod swap_tob_v3_row;
pub mod swap_tob_v3_with_receiver_row;
pub mod swap_v3_row;
pub mod swap_v3_with_cpi_event_row;
pub mod wrap_unwrap_v3_row;
pub mod wrap_unwrap_v3_with_receiver_row;

pub use self::{
    claim_cashback_pumpfun_row::*, claim_cashback_pumpswap_row::*, claim_row::*, cpi_event_row::*,
    create_token_account_row::*, create_token_account_with_seed_row::*, proxy_swap_row::*,
    swap_row::*, swap_tob_v3_enhanced_row::*, swap_tob_v3_row::*, swap_tob_v3_with_receiver_row::*,
    swap_v3_row::*, swap_v3_with_cpi_event_row::*, wrap_unwrap_v3_row::*,
    wrap_unwrap_v3_with_receiver_row::*,
};
use super::OkxDexInstruction;

pub struct OkxDexInstructionsMigration;

impl sqlx_migrator::Migration<sqlx::Postgres> for OkxDexInstructionsMigration {
    fn app(&self) -> &str {
        "okx-dex"
    }

    fn name(&self) -> &str {
        "okx_dex_instructions"
    }

    fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
        vec![
            Box::new(ClaimMigrationOperation),
            Box::new(ClaimCashbackPumpfunMigrationOperation),
            Box::new(ClaimCashbackPumpswapMigrationOperation),
            Box::new(CreateTokenAccountMigrationOperation),
            Box::new(CreateTokenAccountWithSeedMigrationOperation),
            Box::new(ProxySwapMigrationOperation),
            Box::new(SwapMigrationOperation),
            Box::new(SwapTobV3MigrationOperation),
            Box::new(SwapTobV3EnhancedMigrationOperation),
            Box::new(SwapTobV3WithReceiverMigrationOperation),
            Box::new(SwapV3MigrationOperation),
            Box::new(SwapV3WithCpiEventMigrationOperation),
            Box::new(WrapUnwrapV3MigrationOperation),
            Box::new(WrapUnwrapV3WithReceiverMigrationOperation),
            Box::new(CpiEventMigrationOperation),
        ]
    }

    fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
        vec![]
    }
}

pub struct OkxDexInstructionWithMetadata(
    pub OkxDexInstruction,
    pub carbon_core::instruction::InstructionMetadata,
    pub Vec<solana_instruction::AccountMeta>,
);

impl
    From<(
        OkxDexInstruction,
        carbon_core::instruction::InstructionMetadata,
        Vec<solana_instruction::AccountMeta>,
    )> for OkxDexInstructionWithMetadata
{
    fn from(
        value: (
            OkxDexInstruction,
            carbon_core::instruction::InstructionMetadata,
            Vec<solana_instruction::AccountMeta>,
        ),
    ) -> Self {
        OkxDexInstructionWithMetadata(value.0, value.1, value.2)
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for OkxDexInstructionWithMetadata {
    async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let OkxDexInstructionWithMetadata(decoded_instruction, metadata, raw_accounts) = self;
        match decoded_instruction {
            OkxDexInstruction::Claim { data, .. } => {
                let row = claim_row::ClaimRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::ClaimCashbackPumpfun { data, .. } => {
                let row = claim_cashback_pumpfun_row::ClaimCashbackPumpfunRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::ClaimCashbackPumpswap { data, .. } => {
                let row = claim_cashback_pumpswap_row::ClaimCashbackPumpswapRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::CreateTokenAccount { data, .. } => {
                let row = create_token_account_row::CreateTokenAccountRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::CreateTokenAccountWithSeed { data, .. } => {
                let row =
                    create_token_account_with_seed_row::CreateTokenAccountWithSeedRow::from_parts(
                        data.clone(),
                        metadata.clone(),
                        raw_accounts.clone(),
                    );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::ProxySwap { data, .. } => {
                let row = proxy_swap_row::ProxySwapRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::Swap { data, .. } => {
                let row = swap_row::SwapRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapTobV3 { data, .. } => {
                let row = swap_tob_v3_row::SwapTobV3Row::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapTobV3Enhanced { data, .. } => {
                let row = swap_tob_v3_enhanced_row::SwapTobV3EnhancedRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapTobV3WithReceiver { data, .. } => {
                let row = swap_tob_v3_with_receiver_row::SwapTobV3WithReceiverRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapV3 { data, .. } => {
                let row = swap_v3_row::SwapV3Row::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapV3WithCpiEvent { data, .. } => {
                let row = swap_v3_with_cpi_event_row::SwapV3WithCpiEventRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::WrapUnwrapV3 { data, .. } => {
                let row = wrap_unwrap_v3_row::WrapUnwrapV3Row::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::WrapUnwrapV3WithReceiver { data, .. } => {
                let row = wrap_unwrap_v3_with_receiver_row::WrapUnwrapV3WithReceiverRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::CpiEvent { data, .. } => {
                let row = cpi_event_row::CpiEventRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
        }
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for OkxDexInstructionWithMetadata {
    async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let OkxDexInstructionWithMetadata(decoded_instruction, metadata, raw_accounts) = self;
        match decoded_instruction {
            OkxDexInstruction::Claim { data, .. } => {
                let row = claim_row::ClaimRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::ClaimCashbackPumpfun { data, .. } => {
                let row = claim_cashback_pumpfun_row::ClaimCashbackPumpfunRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::ClaimCashbackPumpswap { data, .. } => {
                let row = claim_cashback_pumpswap_row::ClaimCashbackPumpswapRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::CreateTokenAccount { data, .. } => {
                let row = create_token_account_row::CreateTokenAccountRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::CreateTokenAccountWithSeed { data, .. } => {
                let row =
                    create_token_account_with_seed_row::CreateTokenAccountWithSeedRow::from_parts(
                        data.clone(),
                        metadata.clone(),
                        raw_accounts.clone(),
                    );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::ProxySwap { data, .. } => {
                let row = proxy_swap_row::ProxySwapRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::Swap { data, .. } => {
                let row = swap_row::SwapRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapTobV3 { data, .. } => {
                let row = swap_tob_v3_row::SwapTobV3Row::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapTobV3Enhanced { data, .. } => {
                let row = swap_tob_v3_enhanced_row::SwapTobV3EnhancedRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapTobV3WithReceiver { data, .. } => {
                let row = swap_tob_v3_with_receiver_row::SwapTobV3WithReceiverRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapV3 { data, .. } => {
                let row = swap_v3_row::SwapV3Row::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::SwapV3WithCpiEvent { data, .. } => {
                let row = swap_v3_with_cpi_event_row::SwapV3WithCpiEventRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::WrapUnwrapV3 { data, .. } => {
                let row = wrap_unwrap_v3_row::WrapUnwrapV3Row::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::WrapUnwrapV3WithReceiver { data, .. } => {
                let row = wrap_unwrap_v3_with_receiver_row::WrapUnwrapV3WithReceiverRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            OkxDexInstruction::CpiEvent { data, .. } => {
                let row = cpi_event_row::CpiEventRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
        }
    }
}
