//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::{
        AuthorityGraphQL, ExternalPluginAdapterSchemaGraphQL, ExtraAccountGraphQL,
    },
    carbon_core::graphql::primitives::{Json, Pubkey},
    juniper::GraphQLObject,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "LinkedLifecycleHookInitInfo")]
pub struct LinkedLifecycleHookInitInfoGraphQL {
    pub hooked_program: Pubkey,
    pub init_plugin_authority: Option<AuthorityGraphQL>,
    pub lifecycle_checks: Vec<Json>,
    pub extra_accounts: Option<Vec<ExtraAccountGraphQL>>,
    pub data_authority: Option<AuthorityGraphQL>,
    pub schema: Option<ExternalPluginAdapterSchemaGraphQL>,
}

impl From<crate::types::LinkedLifecycleHookInitInfo> for LinkedLifecycleHookInitInfoGraphQL {
    fn from(original: crate::types::LinkedLifecycleHookInitInfo) -> Self {
        Self {
            hooked_program: carbon_core::graphql::primitives::Pubkey(original.hooked_program),
            init_plugin_authority: original.init_plugin_authority.map(|v| v.into()),
            lifecycle_checks: original
                .lifecycle_checks
                .into_iter()
                .map(|item| {
                    carbon_core::graphql::primitives::Json(
                        serde_json::to_value(item).unwrap_or(serde_json::Value::Null),
                    )
                })
                .collect(),
            extra_accounts: original
                .extra_accounts
                .map(|v| v.into_iter().map(|item| item.into()).collect()),
            data_authority: original.data_authority.map(|v| v.into()),
            schema: original.schema.map(|v| v.into()),
        }
    }
}
