//! This code was AUTOGENERATED using the Codama library.
use crate::{PancakeSwapDecoder, PROGRAM_ID};

#[cfg(feature = "postgres")]
pub mod postgres;

#[cfg(feature = "graphql")]
pub mod graphql;

pub mod amm_config;
pub mod observation_state;
pub mod operation_state;
pub mod permissionless_farm_switch;
pub mod personal_position_state;
pub mod pool_state;
pub mod protocol_position_state;
pub mod support_mint_associated;
pub mod tick_array_bitmap_extension;
pub mod tick_array_state;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum PancakeSwapAccount {
    AmmConfig(Box<amm_config::AmmConfig>),
    ObservationState(Box<observation_state::ObservationState>),
    OperationState(Box<operation_state::OperationState>),
    PermissionlessFarmSwitch(Box<permissionless_farm_switch::PermissionlessFarmSwitch>),
    PersonalPositionState(Box<personal_position_state::PersonalPositionState>),
    PoolState(Box<pool_state::PoolState>),
    ProtocolPositionState(Box<protocol_position_state::ProtocolPositionState>),
    SupportMintAssociated(Box<support_mint_associated::SupportMintAssociated>),
    TickArrayBitmapExtension(Box<tick_array_bitmap_extension::TickArrayBitmapExtension>),
    TickArrayState(Box<tick_array_state::TickArrayState>),
}

impl<'a> carbon_core::account::AccountDecoder<'a> for PancakeSwapDecoder {
    type AccountType = PancakeSwapAccount;

    fn decode_account(
        &self,
        account: &'a solana_account::Account,
    ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
        if account.owner != PROGRAM_ID {
            return None;
        }

        let data = account.data.as_slice();

        {
            if let Some(decoded) = amm_config::AmmConfig::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::AmmConfig(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = observation_state::ObservationState::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::ObservationState(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = operation_state::OperationState::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::OperationState(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) =
                permissionless_farm_switch::PermissionlessFarmSwitch::decode(data)
            {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::PermissionlessFarmSwitch(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = personal_position_state::PersonalPositionState::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::PersonalPositionState(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = pool_state::PoolState::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::PoolState(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = protocol_position_state::ProtocolPositionState::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::ProtocolPositionState(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = support_mint_associated::SupportMintAssociated::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::SupportMintAssociated(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) =
                tick_array_bitmap_extension::TickArrayBitmapExtension::decode(data)
            {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::TickArrayBitmapExtension(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = tick_array_state::TickArrayState::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: PancakeSwapAccount::TickArrayState(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }

        None
    }
}
