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

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "TickArrayBitmapExtension")]
pub struct TickArrayBitmapExtensionGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub pool_id: Pubkey,
    pub positive_tick_array_bitmap: Vec<Vec<U64>>,
    pub negative_tick_array_bitmap: Vec<Vec<U64>>,
}

impl TryFrom<crate::accounts::postgres::TickArrayBitmapExtensionRow>
    for TickArrayBitmapExtensionGraphQL
{
    type Error = carbon_core::error::Error;
    fn try_from(
        row: crate::accounts::postgres::TickArrayBitmapExtensionRow,
    ) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            pool_id: carbon_core::graphql::primitives::Pubkey(row.pool_id.0),
            positive_tick_array_bitmap: row
                .positive_tick_array_bitmap
                .0
                .into_iter()
                .map(|item| {
                    item.into_iter()
                        .map(|item| carbon_core::graphql::primitives::U64(*item))
                        .collect()
                })
                .collect(),
            negative_tick_array_bitmap: row
                .negative_tick_array_bitmap
                .0
                .into_iter()
                .map(|item| {
                    item.into_iter()
                        .map(|item| carbon_core::graphql::primitives::U64(*item))
                        .collect()
                })
                .collect(),
        })
    }
}
