//! 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>
//!

pub mod add_supply_row;
pub mod add_tokens_row;
pub mod close_pool_row;
pub mod create_dual_farm_row;
pub mod create_farm_row;
pub mod create_pool_row;
pub mod create_provider_row;
pub mod create_state_row;
pub mod create_triple_farm_row;
pub mod reset_farm_row;
pub mod swap_row;
pub mod update_fees_row;
pub mod update_reward_tokens_row;
pub mod withdraw_buyback_row;
pub mod withdraw_lp_fee_row;
pub mod withdraw_mercanti_fee_row;
pub mod withdraw_project_fee_row;
pub mod withdraw_rewards_row;
pub mod withdraw_shares_row;

pub use self::add_supply_row::*;
pub use self::add_tokens_row::*;
pub use self::close_pool_row::*;
pub use self::create_dual_farm_row::*;
pub use self::create_farm_row::*;
pub use self::create_pool_row::*;
pub use self::create_provider_row::*;
pub use self::create_state_row::*;
pub use self::create_triple_farm_row::*;
pub use self::reset_farm_row::*;
pub use self::swap_row::*;
pub use self::update_fees_row::*;
pub use self::update_reward_tokens_row::*;
pub use self::withdraw_buyback_row::*;
pub use self::withdraw_lp_fee_row::*;
pub use self::withdraw_mercanti_fee_row::*;
pub use self::withdraw_project_fee_row::*;
pub use self::withdraw_rewards_row::*;
pub use self::withdraw_shares_row::*;

use super::BonkswapInstruction;

pub struct BonkswapInstructionsMigration;

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

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

    fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
        vec![
            Box::new(AddSupplyMigrationOperation),
            Box::new(AddTokensMigrationOperation),
            Box::new(ClosePoolMigrationOperation),
            Box::new(CreateDualFarmMigrationOperation),
            Box::new(CreateFarmMigrationOperation),
            Box::new(CreatePoolMigrationOperation),
            Box::new(CreateProviderMigrationOperation),
            Box::new(CreateStateMigrationOperation),
            Box::new(CreateTripleFarmMigrationOperation),
            Box::new(ResetFarmMigrationOperation),
            Box::new(SwapMigrationOperation),
            Box::new(UpdateFeesMigrationOperation),
            Box::new(UpdateRewardTokensMigrationOperation),
            Box::new(WithdrawBuybackMigrationOperation),
            Box::new(WithdrawLpFeeMigrationOperation),
            Box::new(WithdrawMercantiFeeMigrationOperation),
            Box::new(WithdrawProjectFeeMigrationOperation),
            Box::new(WithdrawRewardsMigrationOperation),
            Box::new(WithdrawSharesMigrationOperation),
        ]
    }

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

pub struct BonkswapInstructionWithMetadata(
    pub BonkswapInstruction,
    pub carbon_core::instruction::InstructionMetadata,
);

impl
    From<(
        BonkswapInstruction,
        carbon_core::instruction::InstructionMetadata,
    )> for BonkswapInstructionWithMetadata
{
    fn from(
        value: (
            BonkswapInstruction,
            carbon_core::instruction::InstructionMetadata,
        ),
    ) -> Self {
        BonkswapInstructionWithMetadata(value.0, value.1)
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for BonkswapInstructionWithMetadata {
    async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let BonkswapInstructionWithMetadata(instruction, metadata) = self;
        match instruction {
            BonkswapInstruction::CreatePool(instruction) => {
                let row = create_pool_row::CreatePoolRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateProvider(instruction) => {
                let row = create_provider_row::CreateProviderRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateState(instruction) => {
                let row = create_state_row::CreateStateRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::AddTokens(instruction) => {
                let row =
                    add_tokens_row::AddTokensRow::from_parts(instruction.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawBuyback(instruction) => {
                let row = withdraw_buyback_row::WithdrawBuybackRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::Swap(instruction) => {
                let row = swap_row::SwapRow::from_parts(instruction.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawShares(instruction) => {
                let row = withdraw_shares_row::WithdrawSharesRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawLpFee(instruction) => {
                let row = withdraw_lp_fee_row::WithdrawLpFeeRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawProjectFee(instruction) => {
                let row = withdraw_project_fee_row::WithdrawProjectFeeRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateFarm(instruction) => {
                let row = create_farm_row::CreateFarmRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateDualFarm(instruction) => {
                let row = create_dual_farm_row::CreateDualFarmRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateTripleFarm(instruction) => {
                let row = create_triple_farm_row::CreateTripleFarmRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawRewards(instruction) => {
                let row = withdraw_rewards_row::WithdrawRewardsRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::ClosePool(instruction) => {
                let row =
                    close_pool_row::ClosePoolRow::from_parts(instruction.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawMercantiFee(instruction) => {
                let row = withdraw_mercanti_fee_row::WithdrawMercantiFeeRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::AddSupply(instruction) => {
                let row =
                    add_supply_row::AddSupplyRow::from_parts(instruction.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::UpdateFees(instruction) => {
                let row = update_fees_row::UpdateFeesRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::ResetFarm(instruction) => {
                let row =
                    reset_farm_row::ResetFarmRow::from_parts(instruction.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::UpdateRewardTokens(instruction) => {
                let row = update_reward_tokens_row::UpdateRewardTokensRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
        }
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for BonkswapInstructionWithMetadata {
    async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let BonkswapInstructionWithMetadata(instruction, metadata) = self;
        match instruction {
            BonkswapInstruction::CreatePool(instruction) => {
                let row = create_pool_row::CreatePoolRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateProvider(instruction) => {
                let row = create_provider_row::CreateProviderRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateState(instruction) => {
                let row = create_state_row::CreateStateRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::AddTokens(instruction) => {
                let row =
                    add_tokens_row::AddTokensRow::from_parts(instruction.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawBuyback(instruction) => {
                let row = withdraw_buyback_row::WithdrawBuybackRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::Swap(instruction) => {
                let row = swap_row::SwapRow::from_parts(instruction.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawShares(instruction) => {
                let row = withdraw_shares_row::WithdrawSharesRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawLpFee(instruction) => {
                let row = withdraw_lp_fee_row::WithdrawLpFeeRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawProjectFee(instruction) => {
                let row = withdraw_project_fee_row::WithdrawProjectFeeRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateFarm(instruction) => {
                let row = create_farm_row::CreateFarmRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateDualFarm(instruction) => {
                let row = create_dual_farm_row::CreateDualFarmRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::CreateTripleFarm(instruction) => {
                let row = create_triple_farm_row::CreateTripleFarmRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawRewards(instruction) => {
                let row = withdraw_rewards_row::WithdrawRewardsRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::ClosePool(instruction) => {
                let row =
                    close_pool_row::ClosePoolRow::from_parts(instruction.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::WithdrawMercantiFee(instruction) => {
                let row = withdraw_mercanti_fee_row::WithdrawMercantiFeeRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::AddSupply(instruction) => {
                let row =
                    add_supply_row::AddSupplyRow::from_parts(instruction.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::UpdateFees(instruction) => {
                let row = update_fees_row::UpdateFeesRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::ResetFarm(instruction) => {
                let row =
                    reset_farm_row::ResetFarmRow::from_parts(instruction.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
            BonkswapInstruction::UpdateRewardTokens(instruction) => {
                let row = update_reward_tokens_row::UpdateRewardTokensRow::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
        }
    }
}
