// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: place.atwork.getListings
//
// 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};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{AtUri, Cid};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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::place_atwork::listing::Listing;
use crate::place_atwork::get_listings;
/// A job listing record with metadata for strong references

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListingRecord<S: BosStr = DefaultStr> {
    ///CID of the listing record
    pub cid: Cid<S>,
    ///AT-URI of the listing (at://did/place.atwork.listing/rkey)
    pub uri: AtUri<S>,
    ///The full job listing record
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<Listing<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetListings<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub identity: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tag: Option<S>,
}


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

impl<S: BosStr> LexiconSchema for ListingRecord<S> {
    fn nsid() -> &'static str {
        "place.atwork.getListings"
    }
    fn def_name() -> &'static str {
        "listingRecord"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_atwork_getListings()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `place.atwork.getListings` query.

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

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetListings<S> {
    const NSID: &'static str = "place.atwork.getListings";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetListingsResponse;
}

/** Endpoint marker for the `place.atwork.getListings` query.

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

pub mod listing_record_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 Cid;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCid<St> {}
    impl<St: State> State for SetCid<St> {
        type Cid = Set<members::cid>;
        type Uri = St::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Cid = St::Cid;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

impl<S: BosStr> ListingRecord<S> {
    /// Create a new builder for this type
    pub fn builder() -> ListingRecordBuilder<listing_record_state::Empty, S> {
        ListingRecordBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ListingRecordBuilder<St, S>
where
    St: listing_record_state::State,
    St::Cid: listing_record_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> ListingRecordBuilder<listing_record_state::SetCid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ListingRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ListingRecordBuilder<St, S>
where
    St: listing_record_state::State,
    St::Uri: listing_record_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ListingRecordBuilder<listing_record_state::SetUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ListingRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ListingRecordBuilder<St, S>
where
    St: listing_record_state::State,
    St::Cid: listing_record_state::IsSet,
    St::Uri: listing_record_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ListingRecord<S> {
        ListingRecord {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            value: self._fields.2,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ListingRecord<S> {
        ListingRecord {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            value: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_place_atwork_getListings() -> 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("place.atwork.getListings"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("listingRecord"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A job listing record with metadata for strong references",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("uri"), SmolStr::new_static("cid")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("CID of the listing record"),
                                ),
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "AT-URI of the listing (at://did/place.atwork.listing/rkey)",
                                    ),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("place.atwork.listing"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("identity"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "Filter listings by creator DID (e.g., did:plc:abc123)",
                                            ),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("tag"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("Filter listings by hashtag"),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod get_listings_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 {}
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {}
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {}
}

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

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

impl<S: BosStr> GetListings<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetListingsBuilder<get_listings_state::Empty, S> {
        GetListingsBuilder::builder()
    }
}

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

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

impl<St: get_listings_state::State, S: BosStr> GetListingsBuilder<St, S> {
    /// Set the `identity` field (optional)
    pub fn identity(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `identity` field to an Option value (optional)
    pub fn maybe_identity(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: get_listings_state::State, S: BosStr> GetListingsBuilder<St, S> {
    /// Set the `tag` field (optional)
    pub fn tag(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `tag` field to an Option value (optional)
    pub fn maybe_tag(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> GetListingsBuilder<St, S>
where
    St: get_listings_state::State,
{
    /// Build the final struct.
    pub fn build(self) -> GetListings<S> {
        GetListings {
            identity: self._fields.0,
            tag: self._fields.1,
        }
    }
}