// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.ageassurance.getState
//
// 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;
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::app_bsky::ageassurance::State;
use crate::app_bsky::ageassurance::StateMetadata;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetState<'a> {
    #[serde(borrow)]
    pub country_code: CowStr<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub region_code: Option<CowStr<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetStateOutput<'a> {
    #[serde(borrow)]
    pub metadata: StateMetadata<'a>,
    #[serde(borrow)]
    pub state: State<'a>,
}

/// Response type for app.bsky.ageassurance.getState
pub struct GetStateResponse;
impl jacquard_common::xrpc::XrpcResp for GetStateResponse {
    const NSID: &'static str = "app.bsky.ageassurance.getState";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetStateOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetState<'a> {
    const NSID: &'static str = "app.bsky.ageassurance.getState";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetStateResponse;
}

/// Endpoint type for app.bsky.ageassurance.getState
pub struct GetStateRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetStateRequest {
    const PATH: &'static str = "/xrpc/app.bsky.ageassurance.getState";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetState<'de>;
    type Response = GetStateResponse;
}

pub mod get_state_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 CountryCode;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CountryCode = Unset;
    }
    ///State transition - sets the `country_code` field to Set
    pub struct SetCountryCode<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCountryCode<S> {}
    impl<S: State> State for SetCountryCode<S> {
        type CountryCode = Set<members::country_code>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `country_code` field
        pub struct country_code(());
    }
}

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

impl<'a> GetState<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetStateBuilder<'a, get_state_state::Empty> {
        GetStateBuilder::new()
    }
}

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

impl<'a, S> GetStateBuilder<'a, S>
where
    S: get_state_state::State,
    S::CountryCode: get_state_state::IsUnset,
{
    /// Set the `countryCode` field (required)
    pub fn country_code(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> GetStateBuilder<'a, get_state_state::SetCountryCode<S>> {
        self._fields.0 = Option::Some(value.into());
        GetStateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: get_state_state::State> GetStateBuilder<'a, S> {
    /// Set the `regionCode` field (optional)
    pub fn region_code(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `regionCode` field to an Option value (optional)
    pub fn maybe_region_code(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> GetStateBuilder<'a, S>
where
    S: get_state_state::State,
    S::CountryCode: get_state_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetState<'a> {
        GetState {
            country_code: self._fields.0.unwrap(),
            region_code: self._fields.1,
        }
    }
}