// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atprotofans.validateSupporter
//
// 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::Did;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::com_atprotofans::hydrated_profile::HydratedProfile;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ValidateSupporter<S: BosStr = DefaultStr> {
    pub signer: Did<S>,
    pub subject: Did<S>,
    pub supporter: Did<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ValidateSupporterOutput<S: BosStr = DefaultStr> {
    ///Hydrated profile of the supporter, if available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub profile: Option<HydratedProfile<S>>,
    ///Whether the supporter relationship exists and the required attestation is valid.
    pub valid: bool,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic
)]

#[serde(tag = "error", content = "message")]
pub enum ValidateSupporterError {
    /// Invalid DID format or missing required parameters.
    #[serde(rename = "InvalidRequest")]
    InvalidRequest(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for ValidateSupporterError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::InvalidRequest(msg) => {
                write!(f, "InvalidRequest")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}

/** Response marker for the `com.atprotofans.validateSupporter` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ValidateSupporterOutput<S>` for this endpoint.*/
pub struct ValidateSupporterResponse;
impl jacquard_common::xrpc::XrpcResp for ValidateSupporterResponse {
    const NSID: &'static str = "com.atprotofans.validateSupporter";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ValidateSupporterOutput<S>;
    type Err = ValidateSupporterError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ValidateSupporter<S> {
    const NSID: &'static str = "com.atprotofans.validateSupporter";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ValidateSupporterResponse;
}

/** Endpoint marker for the `com.atprotofans.validateSupporter` query.

Path: `/xrpc/com.atprotofans.validateSupporter`. The request payload type is `ValidateSupporter<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ValidateSupporterRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ValidateSupporterRequest {
    const PATH: &'static str = "/xrpc/com.atprotofans.validateSupporter";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = ValidateSupporter<S>;
    type Response = ValidateSupporterResponse;
}

pub mod validate_supporter_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 Signer;
        type Subject;
        type Supporter;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Signer = Unset;
        type Subject = Unset;
        type Supporter = Unset;
    }
    ///State transition - sets the `signer` field to Set
    pub struct SetSigner<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSigner<St> {}
    impl<St: State> State for SetSigner<St> {
        type Signer = Set<members::signer>;
        type Subject = St::Subject;
        type Supporter = St::Supporter;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSubject<St> {}
    impl<St: State> State for SetSubject<St> {
        type Signer = St::Signer;
        type Subject = Set<members::subject>;
        type Supporter = St::Supporter;
    }
    ///State transition - sets the `supporter` field to Set
    pub struct SetSupporter<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSupporter<St> {}
    impl<St: State> State for SetSupporter<St> {
        type Signer = St::Signer;
        type Subject = St::Subject;
        type Supporter = Set<members::supporter>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `signer` field
        pub struct signer(());
        ///Marker type for the `subject` field
        pub struct subject(());
        ///Marker type for the `supporter` field
        pub struct supporter(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ValidateSupporterBuilder<
    St: validate_supporter_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Did<S>>, Option<Did<S>>, Option<Did<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> ValidateSupporter<S> {
    /// Create a new builder for this type
    pub fn builder() -> ValidateSupporterBuilder<validate_supporter_state::Empty, S> {
        ValidateSupporterBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ValidateSupporterBuilder<St, S>
where
    St: validate_supporter_state::State,
    St::Signer: validate_supporter_state::IsUnset,
{
    /// Set the `signer` field (required)
    pub fn signer(
        mut self,
        value: impl Into<Did<S>>,
    ) -> ValidateSupporterBuilder<validate_supporter_state::SetSigner<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ValidateSupporterBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ValidateSupporterBuilder<St, S>
where
    St: validate_supporter_state::State,
    St::Subject: validate_supporter_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<Did<S>>,
    ) -> ValidateSupporterBuilder<validate_supporter_state::SetSubject<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ValidateSupporterBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ValidateSupporterBuilder<St, S>
where
    St: validate_supporter_state::State,
    St::Supporter: validate_supporter_state::IsUnset,
{
    /// Set the `supporter` field (required)
    pub fn supporter(
        mut self,
        value: impl Into<Did<S>>,
    ) -> ValidateSupporterBuilder<validate_supporter_state::SetSupporter<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ValidateSupporterBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ValidateSupporterBuilder<St, S>
where
    St: validate_supporter_state::State,
    St::Signer: validate_supporter_state::IsSet,
    St::Subject: validate_supporter_state::IsSet,
    St::Supporter: validate_supporter_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ValidateSupporter<S> {
        ValidateSupporter {
            signer: self._fields.0.unwrap(),
            subject: self._fields.1.unwrap(),
            supporter: self._fields.2.unwrap(),
        }
    }
}