// @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;

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListingRecord<'a> {
    ///CID of the listing record
    #[serde(borrow)]
    pub cid: Cid<'a>,
    ///AT-URI of the listing (at://did/place.atwork.listing/rkey)
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    ///The full job listing record
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub value: Option<Listing<'a>>,
}


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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetListingsOutput<'a> {
    #[serde(borrow)]
    pub listings: Vec<get_listings::ListingRecord<'a>>,
}

impl<'a> LexiconSchema for ListingRecord<'a> {
    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 type for place.atwork.getListings
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<'de> = GetListingsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

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

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

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

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

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

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

impl<'a, S: listing_record_state::State> ListingRecordBuilder<'a, S> {
    /// Set the `value` field (optional)
    pub fn value(mut self, value: impl Into<Option<Listing<'a>>>) -> 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<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> ListingRecordBuilder<'a, S>
where
    S: listing_record_state::State,
    S::Uri: listing_record_state::IsSet,
    S::Cid: listing_record_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ListingRecord<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ListingRecord<'a> {
        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<'a, S: get_listings_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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