// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: games.gamesgamesgamesgames.reviewClaim
//
// 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, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::com_atproto::repo::strong_ref::StrongRef;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ReviewClaim<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub approved_games: Option<Vec<AtUri<S>>>,
    pub claim: StrongRef<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<S>,
    pub status: ReviewClaimStatus<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ReviewClaimStatus<S: BosStr = DefaultStr> {
    Approved,
    Denied,
    Other(S),
}

impl<S: BosStr> ReviewClaimStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Approved => "approved",
            Self::Denied => "denied",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "approved" => Self::Approved,
            "denied" => Self::Denied,
            _ => Self::Other(s),
        }
    }
}

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

impl<S: BosStr> AsRef<str> for ReviewClaimStatus<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ReviewClaimStatus<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for ReviewClaimStatus<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for ReviewClaimStatus<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ReviewClaimStatus<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ReviewClaimStatus::Approved => ReviewClaimStatus::Approved,
            ReviewClaimStatus::Denied => ReviewClaimStatus::Denied,
            ReviewClaimStatus::Other(v) => ReviewClaimStatus::Other(v.into_static()),
        }
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ReviewClaimOutput<S: BosStr = DefaultStr> {
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `games.gamesgamesgamesgames.reviewClaim` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ReviewClaimOutput<S>` for this endpoint.*/
pub struct ReviewClaimResponse;
impl jacquard_common::xrpc::XrpcResp for ReviewClaimResponse {
    const NSID: &'static str = "games.gamesgamesgamesgames.reviewClaim";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ReviewClaimOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ReviewClaim<S> {
    const NSID: &'static str = "games.gamesgamesgamesgames.reviewClaim";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = ReviewClaimResponse;
}

/** Endpoint marker for the `games.gamesgamesgamesgames.reviewClaim` procedure.

Path: `/xrpc/games.gamesgamesgamesgames.reviewClaim`. The request payload type is `ReviewClaim<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ReviewClaimRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ReviewClaimRequest {
    const PATH: &'static str = "/xrpc/games.gamesgamesgamesgames.reviewClaim";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = ReviewClaim<S>;
    type Response = ReviewClaimResponse;
}

pub mod review_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 Status;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Claim = Unset;
        type Status = Unset;
    }
    ///State transition - sets the `claim` field to Set
    pub struct SetClaim<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetClaim<St> {}
    impl<St: State> State for SetClaim<St> {
        type Claim = Set<members::claim>;
        type Status = St::Status;
    }
    ///State transition - sets the `status` field to Set
    pub struct SetStatus<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetStatus<St> {}
    impl<St: State> State for SetStatus<St> {
        type Claim = St::Claim;
        type Status = Set<members::status>;
    }
    /// 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 `status` field
        pub struct status(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ReviewClaimBuilder<St: review_claim_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<AtUri<S>>>,
        Option<StrongRef<S>>,
        Option<S>,
        Option<ReviewClaimStatus<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl ReviewClaim<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> ReviewClaimBuilder<review_claim_state::Empty, DefaultStr> {
        ReviewClaimBuilder::new()
    }
}

impl<S: BosStr> ReviewClaim<S> {
    /// Create a new builder for this type
    pub fn builder() -> ReviewClaimBuilder<review_claim_state::Empty, S> {
        ReviewClaimBuilder::builder()
    }
}

impl ReviewClaimBuilder<review_claim_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        ReviewClaimBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> ReviewClaimBuilder<review_claim_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        ReviewClaimBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St: review_claim_state::State, S: BosStr> ReviewClaimBuilder<St, S> {
    /// Set the `approvedGames` field (optional)
    pub fn approved_games(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `approvedGames` field to an Option value (optional)
    pub fn maybe_approved_games(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> ReviewClaimBuilder<St, S>
where
    St: review_claim_state::State,
    St::Claim: review_claim_state::IsUnset,
{
    /// Set the `claim` field (required)
    pub fn claim(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> ReviewClaimBuilder<review_claim_state::SetClaim<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ReviewClaimBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: review_claim_state::State, S: BosStr> ReviewClaimBuilder<St, S> {
    /// Set the `reason` field (optional)
    pub fn reason(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `reason` field to an Option value (optional)
    pub fn maybe_reason(mut self, value: Option<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> ReviewClaimBuilder<St, S>
where
    St: review_claim_state::State,
    St::Status: review_claim_state::IsUnset,
{
    /// Set the `status` field (required)
    pub fn status(
        mut self,
        value: impl Into<ReviewClaimStatus<S>>,
    ) -> ReviewClaimBuilder<review_claim_state::SetStatus<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ReviewClaimBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ReviewClaimBuilder<St, S>
where
    St: review_claim_state::State,
    St::Claim: review_claim_state::IsSet,
    St::Status: review_claim_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ReviewClaim<S> {
        ReviewClaim {
            approved_games: self._fields.0,
            claim: self._fields.1.unwrap(),
            reason: 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<SmolStr, Data<S>>,
    ) -> ReviewClaim<S> {
        ReviewClaim {
            approved_games: self._fields.0,
            claim: self._fields.1.unwrap(),
            reason: self._fields.2,
            status: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}