// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: systems.timker.hawlt.putNote
//
// 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::types::string::{AtUri, Cid, RecordKey, Rkey};
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::systems_timker::hawlt::note::Note;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PutNote<'a> {
    ///The note record to write.
    #[serde(borrow)]
    pub record: Note<'a>,
    ///The record key (TID) for this note.
    #[serde(borrow)]
    pub rkey: RecordKey<Rkey<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PutNoteOutput<'a> {
    #[serde(borrow)]
    pub cid: Cid<'a>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}

/// Response type for systems.timker.hawlt.putNote
pub struct PutNoteResponse;
impl jacquard_common::xrpc::XrpcResp for PutNoteResponse {
    const NSID: &'static str = "systems.timker.hawlt.putNote";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = PutNoteOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for PutNote<'a> {
    const NSID: &'static str = "systems.timker.hawlt.putNote";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = PutNoteResponse;
}

/// Endpoint type for systems.timker.hawlt.putNote
pub struct PutNoteRequest;
impl jacquard_common::xrpc::XrpcEndpoint for PutNoteRequest {
    const PATH: &'static str = "/xrpc/systems.timker.hawlt.putNote";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = PutNote<'de>;
    type Response = PutNoteResponse;
}

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

/// Builder for constructing an instance of this type
pub struct PutNoteBuilder<'a, S: put_note_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Note<'a>>, Option<RecordKey<Rkey<'a>>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> PutNote<'a> {
    /// Create a new builder for this type
    pub fn new() -> PutNoteBuilder<'a, put_note_state::Empty> {
        PutNoteBuilder::new()
    }
}

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

impl<'a, S> PutNoteBuilder<'a, S>
where
    S: put_note_state::State,
    S::Record: put_note_state::IsUnset,
{
    /// Set the `record` field (required)
    pub fn record(
        mut self,
        value: impl Into<Note<'a>>,
    ) -> PutNoteBuilder<'a, put_note_state::SetRecord<S>> {
        self._fields.0 = Option::Some(value.into());
        PutNoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PutNoteBuilder<'a, S>
where
    S: put_note_state::State,
    S::Rkey: put_note_state::IsUnset,
{
    /// Set the `rkey` field (required)
    pub fn rkey(
        mut self,
        value: impl Into<RecordKey<Rkey<'a>>>,
    ) -> PutNoteBuilder<'a, put_note_state::SetRkey<S>> {
        self._fields.1 = Option::Some(value.into());
        PutNoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PutNoteBuilder<'a, S>
where
    S: put_note_state::State,
    S::Rkey: put_note_state::IsSet,
    S::Record: put_note_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> PutNote<'a> {
        PutNote {
            record: self._fields.0.unwrap(),
            rkey: self._fields.1.unwrap(),
            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>,
        >,
    ) -> PutNote<'a> {
        PutNote {
            record: self._fields.0.unwrap(),
            rkey: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}