pub mod closed;
pub mod open;
#[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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
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};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct State<'a> {
#[serde(borrow)]
pub issue: AtUri<'a>,
#[serde(borrow)]
pub state: StateState<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StateState<'a> {
ShTangledRepoIssueStateOpen,
ShTangledRepoIssueStateClosed,
Other(CowStr<'a>),
}
impl<'a> StateState<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::ShTangledRepoIssueStateOpen => "sh.tangled.repo.issue.state.open",
Self::ShTangledRepoIssueStateClosed => "sh.tangled.repo.issue.state.closed",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for StateState<'a> {
fn from(s: &'a str) -> Self {
match s {
"sh.tangled.repo.issue.state.open" => Self::ShTangledRepoIssueStateOpen,
"sh.tangled.repo.issue.state.closed" => Self::ShTangledRepoIssueStateClosed,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for StateState<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"sh.tangled.repo.issue.state.open" => Self::ShTangledRepoIssueStateOpen,
"sh.tangled.repo.issue.state.closed" => Self::ShTangledRepoIssueStateClosed,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for StateState<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for StateState<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for StateState<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for StateState<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for StateState<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for StateState<'_> {
type Output = StateState<'static>;
fn into_static(self) -> Self::Output {
match self {
StateState::ShTangledRepoIssueStateOpen => {
StateState::ShTangledRepoIssueStateOpen
}
StateState::ShTangledRepoIssueStateClosed => {
StateState::ShTangledRepoIssueStateClosed
}
StateState::Other(v) => StateState::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct StateGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: State<'a>,
}
impl<'a> State<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, StateRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct StateRecord;
impl XrpcResp for StateRecord {
const NSID: &'static str = "sh.tangled.repo.issue.state";
const ENCODING: &'static str = "application/json";
type Output<'de> = StateGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<StateGetRecordOutput<'_>> for State<'_> {
fn from(output: StateGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for State<'_> {
const NSID: &'static str = "sh.tangled.repo.issue.state";
type Record = StateRecord;
}
impl Collection for StateRecord {
const NSID: &'static str = "sh.tangled.repo.issue.state";
type Record = StateRecord;
}
impl<'a> LexiconSchema for State<'a> {
fn nsid() -> &'static str {
"sh.tangled.repo.issue.state"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_repo_issue_state()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod state_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type State;
type Issue;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type State = Unset;
type Issue = Unset;
}
pub struct SetState<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetState<S> {}
impl<S: State> State for SetState<S> {
type State = Set<members::state>;
type Issue = S::Issue;
}
pub struct SetIssue<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetIssue<S> {}
impl<S: State> State for SetIssue<S> {
type State = S::State;
type Issue = Set<members::issue>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct state(());
pub struct issue(());
}
}
pub struct StateBuilder<'a, S: state_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<AtUri<'a>>, Option<StateState<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> State<'a> {
pub fn new() -> StateBuilder<'a, state_state::Empty> {
StateBuilder::new()
}
}
impl<'a> StateBuilder<'a, state_state::Empty> {
pub fn new() -> Self {
StateBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> StateBuilder<'a, S>
where
S: state_state::State,
S::Issue: state_state::IsUnset,
{
pub fn issue(
mut self,
value: impl Into<AtUri<'a>>,
) -> StateBuilder<'a, state_state::SetIssue<S>> {
self._fields.0 = Option::Some(value.into());
StateBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> StateBuilder<'a, S>
where
S: state_state::State,
S::State: state_state::IsUnset,
{
pub fn state(
mut self,
value: impl Into<StateState<'a>>,
) -> StateBuilder<'a, state_state::SetState<S>> {
self._fields.1 = Option::Some(value.into());
StateBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> StateBuilder<'a, S>
where
S: state_state::State,
S::State: state_state::IsSet,
S::Issue: state_state::IsSet,
{
pub fn build(self) -> State<'a> {
State {
issue: self._fields.0.unwrap(),
state: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> State<'a> {
State {
issue: self._fields.0.unwrap(),
state: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_sh_tangled_repo_issue_state() -> 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("sh.tangled.repo.issue.state"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("issue"), SmolStr::new_static("state")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("issue"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("state"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("state of the issue")),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}