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

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "OperationState")]
pub struct OperationStateGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub bump: U8,
    pub operation_owners: Vec<Pubkey>,
    pub whitelist_mints: Vec<Pubkey>,
}

impl TryFrom<crate::accounts::postgres::OperationStateRow> for OperationStateGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::OperationStateRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            bump: carbon_core::graphql::primitives::U8((*row.bump) as u8),
            operation_owners: row
                .operation_owners
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::Pubkey(item.0))
                .collect(),
            whitelist_mints: row
                .whitelist_mints
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::Pubkey(item.0))
                .collect(),
        })
    }
}
