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

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "TickArrayState")]
pub struct TickArrayStateGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub pool_id: Pubkey,
    pub start_tick_index: i32,
    pub ticks: Vec<TickStateGraphQL>,
    pub initialized_tick_count: U8,
    pub recent_epoch: U64,
    pub padding: Vec<U8>,
}

impl TryFrom<crate::accounts::postgres::TickArrayStateRow> for TickArrayStateGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::TickArrayStateRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            pool_id: carbon_core::graphql::primitives::Pubkey(row.pool_id.0),
            start_tick_index: row.start_tick_index,
            ticks: row.ticks.0.into_iter().map(|item| item.into()).collect(),
            initialized_tick_count: carbon_core::graphql::primitives::U8(
                (*row.initialized_tick_count) as u8,
            ),
            recent_epoch: carbon_core::graphql::primitives::U64(*row.recent_epoch),
            padding: row
                .padding
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
        })
    }
}
