#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::app_bsky::richtext::facet::Facet;
use crate::community_lexicon::location::hthree::Hthree;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "place.atwork.listing",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Listing<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub apply_link: Option<UriValue<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub banner: Option<BlobRef<S>>,
pub description: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub facets: Option<Vec<Facet<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub locations: Option<Vec<Hthree<S>>>,
pub not_after: Datetime,
pub not_before: Datetime,
pub title: 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")]
pub struct ListingGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Listing<S>,
}
impl<S: BosStr> Listing<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ListingRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ListingRecord;
impl XrpcResp for ListingRecord {
const NSID: &'static str = "place.atwork.listing";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ListingGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ListingGetRecordOutput<S>> for Listing<S> {
fn from(output: ListingGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Listing<S> {
const NSID: &'static str = "place.atwork.listing";
type Record = ListingRecord;
}
impl Collection for ListingRecord {
const NSID: &'static str = "place.atwork.listing";
type Record = ListingRecord;
}
impl<S: BosStr> LexiconSchema for Listing<S> {
fn nsid() -> &'static str {
"place.atwork.listing"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_place_atwork_listing()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.banner {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("banner"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.banner {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/png", "image/jpeg"];
let matched = accepted.iter().any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix) && mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("banner"),
accepted: vec!["image/png".to_string(), "image/jpeg".to_string()],
actual: mime.to_string(),
});
}
}
}
{
let value = &self.description;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 10000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.description;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 10000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("description"),
max: 10000usize,
actual: count,
});
}
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 200usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 200usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod listing_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Title;
type Description;
type NotAfter;
type NotBefore;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type Description = Unset;
type NotAfter = Unset;
type NotBefore = Unset;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type Title = Set<members::title>;
type Description = St::Description;
type NotAfter = St::NotAfter;
type NotBefore = St::NotBefore;
}
pub struct SetDescription<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDescription<St> {}
impl<St: State> State for SetDescription<St> {
type Title = St::Title;
type Description = Set<members::description>;
type NotAfter = St::NotAfter;
type NotBefore = St::NotBefore;
}
pub struct SetNotAfter<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetNotAfter<St> {}
impl<St: State> State for SetNotAfter<St> {
type Title = St::Title;
type Description = St::Description;
type NotAfter = Set<members::not_after>;
type NotBefore = St::NotBefore;
}
pub struct SetNotBefore<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetNotBefore<St> {}
impl<St: State> State for SetNotBefore<St> {
type Title = St::Title;
type Description = St::Description;
type NotAfter = St::NotAfter;
type NotBefore = Set<members::not_before>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct description(());
pub struct not_after(());
pub struct not_before(());
}
}
pub struct ListingBuilder<S: BosStr, St: listing_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<UriValue<S>>,
Option<BlobRef<S>>,
Option<S>,
Option<Vec<Facet<S>>>,
Option<Vec<Hthree<S>>>,
Option<Datetime>,
Option<Datetime>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Listing<S> {
pub fn new() -> ListingBuilder<S, listing_state::Empty> {
ListingBuilder::new()
}
}
impl<S: BosStr> ListingBuilder<S, listing_state::Empty> {
pub fn new() -> Self {
ListingBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: listing_state::State> ListingBuilder<S, St> {
pub fn apply_link(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_apply_link(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: listing_state::State> ListingBuilder<S, St> {
pub fn banner(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_banner(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> ListingBuilder<S, St>
where
St: listing_state::State,
St::Description: listing_state::IsUnset,
{
pub fn description(
mut self,
value: impl Into<S>,
) -> ListingBuilder<S, listing_state::SetDescription<St>> {
self._fields.2 = Option::Some(value.into());
ListingBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: listing_state::State> ListingBuilder<S, St> {
pub fn facets(mut self, value: impl Into<Option<Vec<Facet<S>>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_facets(mut self, value: Option<Vec<Facet<S>>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: listing_state::State> ListingBuilder<S, St> {
pub fn locations(mut self, value: impl Into<Option<Vec<Hthree<S>>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_locations(mut self, value: Option<Vec<Hthree<S>>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> ListingBuilder<S, St>
where
St: listing_state::State,
St::NotAfter: listing_state::IsUnset,
{
pub fn not_after(
mut self,
value: impl Into<Datetime>,
) -> ListingBuilder<S, listing_state::SetNotAfter<St>> {
self._fields.5 = Option::Some(value.into());
ListingBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ListingBuilder<S, St>
where
St: listing_state::State,
St::NotBefore: listing_state::IsUnset,
{
pub fn not_before(
mut self,
value: impl Into<Datetime>,
) -> ListingBuilder<S, listing_state::SetNotBefore<St>> {
self._fields.6 = Option::Some(value.into());
ListingBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ListingBuilder<S, St>
where
St: listing_state::State,
St::Title: listing_state::IsUnset,
{
pub fn title(mut self, value: impl Into<S>) -> ListingBuilder<S, listing_state::SetTitle<St>> {
self._fields.7 = Option::Some(value.into());
ListingBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ListingBuilder<S, St>
where
St: listing_state::State,
St::Title: listing_state::IsSet,
St::Description: listing_state::IsSet,
St::NotAfter: listing_state::IsSet,
St::NotBefore: listing_state::IsSet,
{
pub fn build(self) -> Listing<S> {
Listing {
apply_link: self._fields.0,
banner: self._fields.1,
description: self._fields.2.unwrap(),
facets: self._fields.3,
locations: self._fields.4,
not_after: self._fields.5.unwrap(),
not_before: self._fields.6.unwrap(),
title: self._fields.7.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Listing<S> {
Listing {
apply_link: self._fields.0,
banner: self._fields.1,
description: self._fields.2.unwrap(),
facets: self._fields.3,
locations: self._fields.4,
not_after: self._fields.5.unwrap(),
not_before: self._fields.6.unwrap(),
title: self._fields.7.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_place_atwork_listing() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("place.atwork.listing"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(CowStr::new_static("A job listing")),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"),
SmolStr::new_static("notBefore"),
SmolStr::new_static("notAfter"),
SmolStr::new_static("description")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("applyLink"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"URL where applicants can apply for the job.",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("banner"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The description of the job listing."),
),
max_length: Some(10000usize),
max_graphemes: Some(10000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("facets"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Annotations of text (mentions, URLs, hashtags, etc).",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("app.bsky.richtext.facet"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("locations"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Locations that are relevant to the job listing.",
),
),
items: LexArrayItem::Union(LexRefUnion {
refs: vec![
CowStr::new_static("community.lexicon.location.hthree")
],
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("notAfter"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when the job listing expires.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("notBefore"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp when the job listing becomes visible.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The title of the job listing."),
),
max_length: Some(200usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}