// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: games.gamesgamesgamesgames.migrateClaim
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::AtUri;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::games_gamesgamesgamesgames::migrate_claim;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct MigrateClaim<'a> {
    #[serde(borrow)]
    pub claim: AtUri<'a>,
    #[serde(borrow)]
    pub claim_review: AtUri<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct MigrateClaimOutput<'a> {
    #[serde(borrow)]
    pub results: Vec<migrate_claim::MigrationResult<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct MigrationResult<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub error: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub game_uri: AtUri<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub new_uri: Option<AtUri<'a>>,
    #[serde(borrow)]
    pub status: MigrationResultStatus<'a>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum MigrationResultStatus<'a> {
    Success,
    Failed,
    Skipped,
    Other(CowStr<'a>),
}

impl<'a> MigrationResultStatus<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Success => "success",
            Self::Failed => "failed",
            Self::Skipped => "skipped",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for MigrationResultStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "success" => Self::Success,
            "failed" => Self::Failed,
            "skipped" => Self::Skipped,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for MigrationResultStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "success" => Self::Success,
            "failed" => Self::Failed,
            "skipped" => Self::Skipped,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> core::fmt::Display for MigrationResultStatus<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> AsRef<str> for MigrationResultStatus<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for MigrationResultStatus<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for MigrationResultStatus<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for MigrationResultStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for MigrationResultStatus<'_> {
    type Output = MigrationResultStatus<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            MigrationResultStatus::Success => MigrationResultStatus::Success,
            MigrationResultStatus::Failed => MigrationResultStatus::Failed,
            MigrationResultStatus::Skipped => MigrationResultStatus::Skipped,
            MigrationResultStatus::Other(v) => {
                MigrationResultStatus::Other(v.into_static())
            }
        }
    }
}

/// Response type for games.gamesgamesgamesgames.migrateClaim
pub struct MigrateClaimResponse;
impl jacquard_common::xrpc::XrpcResp for MigrateClaimResponse {
    const NSID: &'static str = "games.gamesgamesgamesgames.migrateClaim";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = MigrateClaimOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for MigrateClaim<'a> {
    const NSID: &'static str = "games.gamesgamesgamesgames.migrateClaim";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = MigrateClaimResponse;
}

/// Endpoint type for games.gamesgamesgamesgames.migrateClaim
pub struct MigrateClaimRequest;
impl jacquard_common::xrpc::XrpcEndpoint for MigrateClaimRequest {
    const PATH: &'static str = "/xrpc/games.gamesgamesgamesgames.migrateClaim";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = MigrateClaim<'de>;
    type Response = MigrateClaimResponse;
}

impl<'a> LexiconSchema for MigrationResult<'a> {
    fn nsid() -> &'static str {
        "games.gamesgamesgamesgames.migrateClaim"
    }
    fn def_name() -> &'static str {
        "migrationResult"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_games_gamesgamesgamesgames_migrateClaim()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod migrate_claim_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Claim;
        type ClaimReview;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Claim = Unset;
        type ClaimReview = Unset;
    }
    ///State transition - sets the `claim` field to Set
    pub struct SetClaim<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetClaim<S> {}
    impl<S: State> State for SetClaim<S> {
        type Claim = Set<members::claim>;
        type ClaimReview = S::ClaimReview;
    }
    ///State transition - sets the `claim_review` field to Set
    pub struct SetClaimReview<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetClaimReview<S> {}
    impl<S: State> State for SetClaimReview<S> {
        type Claim = S::Claim;
        type ClaimReview = Set<members::claim_review>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `claim` field
        pub struct claim(());
        ///Marker type for the `claim_review` field
        pub struct claim_review(());
    }
}

/// Builder for constructing an instance of this type
pub struct MigrateClaimBuilder<'a, S: migrate_claim_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<AtUri<'a>>, Option<AtUri<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> MigrateClaim<'a> {
    /// Create a new builder for this type
    pub fn new() -> MigrateClaimBuilder<'a, migrate_claim_state::Empty> {
        MigrateClaimBuilder::new()
    }
}

impl<'a> MigrateClaimBuilder<'a, migrate_claim_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        MigrateClaimBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MigrateClaimBuilder<'a, S>
where
    S: migrate_claim_state::State,
    S::Claim: migrate_claim_state::IsUnset,
{
    /// Set the `claim` field (required)
    pub fn claim(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> MigrateClaimBuilder<'a, migrate_claim_state::SetClaim<S>> {
        self._fields.0 = Option::Some(value.into());
        MigrateClaimBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MigrateClaimBuilder<'a, S>
where
    S: migrate_claim_state::State,
    S::ClaimReview: migrate_claim_state::IsUnset,
{
    /// Set the `claimReview` field (required)
    pub fn claim_review(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> MigrateClaimBuilder<'a, migrate_claim_state::SetClaimReview<S>> {
        self._fields.1 = Option::Some(value.into());
        MigrateClaimBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MigrateClaimBuilder<'a, S>
where
    S: migrate_claim_state::State,
    S::Claim: migrate_claim_state::IsSet,
    S::ClaimReview: migrate_claim_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> MigrateClaim<'a> {
        MigrateClaim {
            claim: self._fields.0.unwrap(),
            claim_review: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> MigrateClaim<'a> {
        MigrateClaim {
            claim: self._fields.0.unwrap(),
            claim_review: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod migration_result_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type GameUri;
        type Status;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type GameUri = Unset;
        type Status = Unset;
    }
    ///State transition - sets the `game_uri` field to Set
    pub struct SetGameUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetGameUri<S> {}
    impl<S: State> State for SetGameUri<S> {
        type GameUri = Set<members::game_uri>;
        type Status = S::Status;
    }
    ///State transition - sets the `status` field to Set
    pub struct SetStatus<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetStatus<S> {}
    impl<S: State> State for SetStatus<S> {
        type GameUri = S::GameUri;
        type Status = Set<members::status>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `game_uri` field
        pub struct game_uri(());
        ///Marker type for the `status` field
        pub struct status(());
    }
}

/// Builder for constructing an instance of this type
pub struct MigrationResultBuilder<'a, S: migration_result_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<AtUri<'a>>,
        Option<AtUri<'a>>,
        Option<MigrationResultStatus<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> MigrationResult<'a> {
    /// Create a new builder for this type
    pub fn new() -> MigrationResultBuilder<'a, migration_result_state::Empty> {
        MigrationResultBuilder::new()
    }
}

impl<'a> MigrationResultBuilder<'a, migration_result_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        MigrationResultBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: migration_result_state::State> MigrationResultBuilder<'a, S> {
    /// Set the `error` field (optional)
    pub fn error(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `error` field to an Option value (optional)
    pub fn maybe_error(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> MigrationResultBuilder<'a, S>
where
    S: migration_result_state::State,
    S::GameUri: migration_result_state::IsUnset,
{
    /// Set the `gameUri` field (required)
    pub fn game_uri(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> MigrationResultBuilder<'a, migration_result_state::SetGameUri<S>> {
        self._fields.1 = Option::Some(value.into());
        MigrationResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: migration_result_state::State> MigrationResultBuilder<'a, S> {
    /// Set the `newUri` field (optional)
    pub fn new_uri(mut self, value: impl Into<Option<AtUri<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `newUri` field to an Option value (optional)
    pub fn maybe_new_uri(mut self, value: Option<AtUri<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> MigrationResultBuilder<'a, S>
where
    S: migration_result_state::State,
    S::Status: migration_result_state::IsUnset,
{
    /// Set the `status` field (required)
    pub fn status(
        mut self,
        value: impl Into<MigrationResultStatus<'a>>,
    ) -> MigrationResultBuilder<'a, migration_result_state::SetStatus<S>> {
        self._fields.3 = Option::Some(value.into());
        MigrationResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MigrationResultBuilder<'a, S>
where
    S: migration_result_state::State,
    S::GameUri: migration_result_state::IsSet,
    S::Status: migration_result_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> MigrationResult<'a> {
        MigrationResult {
            error: self._fields.0,
            game_uri: self._fields.1.unwrap(),
            new_uri: self._fields.2,
            status: self._fields.3.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> MigrationResult<'a> {
        MigrationResult {
            error: self._fields.0,
            game_uri: self._fields.1.unwrap(),
            new_uri: self._fields.2,
            status: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_games_gamesgamesgamesgames_migrateClaim() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("games.gamesgamesgamesgames.migrateClaim"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcProcedure(LexXrpcProcedure {
                    input: Some(LexXrpcBody {
                        encoding: CowStr::new_static("application/json"),
                        schema: Some(
                            LexXrpcBodySchema::Object(LexObject {
                                required: Some(
                                    vec![
                                        SmolStr::new_static("claim"),
                                        SmolStr::new_static("claimReview")
                                    ],
                                ),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("claim"),
                                        LexObjectProperty::String(LexString {
                                            format: Some(LexStringFormat::AtUri),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("claimReview"),
                                        LexObjectProperty::String(LexString {
                                            format: Some(LexStringFormat::AtUri),
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("migrationResult"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("gameUri"), SmolStr::new_static("status")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("error"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("gameUri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("newUri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("status"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}