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

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "ExternalRegistryRecord")]
pub struct ExternalRegistryRecordGraphQL {
    pub plugin_type: ExternalPluginAdapterTypeGraphQL,
    pub authority: AuthorityGraphQL,
    pub lifecycle_checks: Option<Vec<Json>>,
    pub offset: U64,
    pub data_offset: Option<U64>,
    pub data_len: Option<U64>,
}

impl From<crate::types::ExternalRegistryRecord> for ExternalRegistryRecordGraphQL {
    fn from(original: crate::types::ExternalRegistryRecord) -> Self {
        Self {
            plugin_type: original.plugin_type.into(),
            authority: original.authority.into(),
            lifecycle_checks: original.lifecycle_checks.map(|v| {
                v.into_iter()
                    .map(|item| {
                        carbon_core::graphql::primitives::Json(
                            serde_json::to_value(item).unwrap_or(serde_json::Value::Null),
                        )
                    })
                    .collect()
            }),
            offset: carbon_core::graphql::primitives::U64(original.offset),
            data_offset: original
                .data_offset
                .map(carbon_core::graphql::primitives::U64),
            data_len: original.data_len.map(carbon_core::graphql::primitives::U64),
        }
    }
}
