//! This code was AUTOGENERATED using the Codama library.
use {
    carbon_core::graphql::primitives::{Pubkey, U32, U64, U8},
    juniper::GraphQLObject,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "AmmConfig")]
pub struct AmmConfigGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub bump: U8,
    pub index: i32,
    pub owner: Pubkey,
    pub protocol_fee_rate: U32,
    pub trade_fee_rate: U32,
    pub tick_spacing: i32,
    pub fund_fee_rate: U32,
    pub padding_u32: U32,
    pub fund_owner: Pubkey,
    pub padding: Vec<U64>,
}

impl TryFrom<crate::accounts::postgres::AmmConfigRow> for AmmConfigGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::AmmConfigRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            bump: carbon_core::graphql::primitives::U8((*row.bump) as u8),
            index: *row.index,
            owner: carbon_core::graphql::primitives::Pubkey(row.owner.0),
            protocol_fee_rate: carbon_core::graphql::primitives::U32(
                (*row.protocol_fee_rate) as u32,
            ),
            trade_fee_rate: carbon_core::graphql::primitives::U32((*row.trade_fee_rate) as u32),
            tick_spacing: *row.tick_spacing,
            fund_fee_rate: carbon_core::graphql::primitives::U32((*row.fund_fee_rate) as u32),
            padding_u32: carbon_core::graphql::primitives::U32((*row.padding_u32) as u32),
            fund_owner: carbon_core::graphql::primitives::Pubkey(row.fund_owner.0),
            padding: row
                .padding
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
        })
    }
}
