// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: network.slices.slice.getJobLogs
//
// 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::{Did, Datetime};
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::network_slices::slice::get_job_logs;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LogEntry<S: BosStr = DefaultStr> {
    ///When the log entry was created
    pub created_at: Datetime,
    ///Log entry ID
    pub id: i64,
    ///UUID of related job if applicable
    #[serde(skip_serializing_if = "Option::is_none")]
    pub job_id: Option<S>,
    ///Log level
    pub level: S,
    ///Type of log entry
    pub log_type: S,
    ///Log message
    pub message: S,
    ///Additional metadata associated with the log entry
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<Data<S>>,
    ///AT-URI of related slice if applicable
    #[serde(skip_serializing_if = "Option::is_none")]
    pub slice_uri: Option<S>,
    ///DID of related user if applicable
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_did: Option<Did<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 GetJobLogs<S: BosStr = DefaultStr> {
    pub job_id: S,
    /// Defaults to `100`. Min: 1. Max: 1000.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


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

impl<S: BosStr> LexiconSchema for LogEntry<S> {
    fn nsid() -> &'static str {
        "network.slices.slice.getJobLogs"
    }
    fn def_name() -> &'static str {
        "logEntry"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_slice_getJobLogs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `network.slices.slice.getJobLogs` query.

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

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetJobLogs<S> {
    const NSID: &'static str = "network.slices.slice.getJobLogs";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetJobLogsResponse;
}

/** Endpoint marker for the `network.slices.slice.getJobLogs` query.

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

pub mod log_entry_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 CreatedAt;
        type Id;
        type Level;
        type LogType;
        type Message;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Id = Unset;
        type Level = Unset;
        type LogType = Unset;
        type Message = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type Id = St::Id;
        type Level = St::Level;
        type LogType = St::LogType;
        type Message = St::Message;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetId<St> {}
    impl<St: State> State for SetId<St> {
        type CreatedAt = St::CreatedAt;
        type Id = Set<members::id>;
        type Level = St::Level;
        type LogType = St::LogType;
        type Message = St::Message;
    }
    ///State transition - sets the `level` field to Set
    pub struct SetLevel<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLevel<St> {}
    impl<St: State> State for SetLevel<St> {
        type CreatedAt = St::CreatedAt;
        type Id = St::Id;
        type Level = Set<members::level>;
        type LogType = St::LogType;
        type Message = St::Message;
    }
    ///State transition - sets the `log_type` field to Set
    pub struct SetLogType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLogType<St> {}
    impl<St: State> State for SetLogType<St> {
        type CreatedAt = St::CreatedAt;
        type Id = St::Id;
        type Level = St::Level;
        type LogType = Set<members::log_type>;
        type Message = St::Message;
    }
    ///State transition - sets the `message` field to Set
    pub struct SetMessage<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMessage<St> {}
    impl<St: State> State for SetMessage<St> {
        type CreatedAt = St::CreatedAt;
        type Id = St::Id;
        type Level = St::Level;
        type LogType = St::LogType;
        type Message = Set<members::message>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `level` field
        pub struct level(());
        ///Marker type for the `log_type` field
        pub struct log_type(());
        ///Marker type for the `message` field
        pub struct message(());
    }
}

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

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

impl<S: BosStr> LogEntry<S> {
    /// Create a new builder for this type
    pub fn builder() -> LogEntryBuilder<log_entry_state::Empty, S> {
        LogEntryBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> LogEntryBuilder<St, S>
where
    St: log_entry_state::State,
    St::CreatedAt: log_entry_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> LogEntryBuilder<log_entry_state::SetCreatedAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        LogEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LogEntryBuilder<St, S>
where
    St: log_entry_state::State,
    St::Id: log_entry_state::IsUnset,
{
    /// Set the `id` field (required)
    pub fn id(
        mut self,
        value: impl Into<i64>,
    ) -> LogEntryBuilder<log_entry_state::SetId<St>, S> {
        self._fields.1 = Option::Some(value.into());
        LogEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> LogEntryBuilder<St, S>
where
    St: log_entry_state::State,
    St::Level: log_entry_state::IsUnset,
{
    /// Set the `level` field (required)
    pub fn level(
        mut self,
        value: impl Into<S>,
    ) -> LogEntryBuilder<log_entry_state::SetLevel<St>, S> {
        self._fields.3 = Option::Some(value.into());
        LogEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LogEntryBuilder<St, S>
where
    St: log_entry_state::State,
    St::LogType: log_entry_state::IsUnset,
{
    /// Set the `logType` field (required)
    pub fn log_type(
        mut self,
        value: impl Into<S>,
    ) -> LogEntryBuilder<log_entry_state::SetLogType<St>, S> {
        self._fields.4 = Option::Some(value.into());
        LogEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LogEntryBuilder<St, S>
where
    St: log_entry_state::State,
    St::Message: log_entry_state::IsUnset,
{
    /// Set the `message` field (required)
    pub fn message(
        mut self,
        value: impl Into<S>,
    ) -> LogEntryBuilder<log_entry_state::SetMessage<St>, S> {
        self._fields.5 = Option::Some(value.into());
        LogEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: log_entry_state::State, S: BosStr> LogEntryBuilder<St, S> {
    /// Set the `metadata` field (optional)
    pub fn metadata(mut self, value: impl Into<Option<Data<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `metadata` field to an Option value (optional)
    pub fn maybe_metadata(mut self, value: Option<Data<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: log_entry_state::State, S: BosStr> LogEntryBuilder<St, S> {
    /// Set the `sliceUri` field (optional)
    pub fn slice_uri(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `sliceUri` field to an Option value (optional)
    pub fn maybe_slice_uri(mut self, value: Option<S>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St: log_entry_state::State, S: BosStr> LogEntryBuilder<St, S> {
    /// Set the `userDid` field (optional)
    pub fn user_did(mut self, value: impl Into<Option<Did<S>>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `userDid` field to an Option value (optional)
    pub fn maybe_user_did(mut self, value: Option<Did<S>>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St, S: BosStr> LogEntryBuilder<St, S>
where
    St: log_entry_state::State,
    St::CreatedAt: log_entry_state::IsSet,
    St::Id: log_entry_state::IsSet,
    St::Level: log_entry_state::IsSet,
    St::LogType: log_entry_state::IsSet,
    St::Message: log_entry_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> LogEntry<S> {
        LogEntry {
            created_at: self._fields.0.unwrap(),
            id: self._fields.1.unwrap(),
            job_id: self._fields.2,
            level: self._fields.3.unwrap(),
            log_type: self._fields.4.unwrap(),
            message: self._fields.5.unwrap(),
            metadata: self._fields.6,
            slice_uri: self._fields.7,
            user_did: self._fields.8,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> LogEntry<S> {
        LogEntry {
            created_at: self._fields.0.unwrap(),
            id: self._fields.1.unwrap(),
            job_id: self._fields.2,
            level: self._fields.3.unwrap(),
            log_type: self._fields.4.unwrap(),
            message: self._fields.5.unwrap(),
            metadata: self._fields.6,
            slice_uri: self._fields.7,
            user_did: self._fields.8,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_network_slices_slice_getJobLogs() -> 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("network.slices.slice.getJobLogs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("logEntry"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("id"), SmolStr::new_static("createdAt"),
                            SmolStr::new_static("logType"), SmolStr::new_static("level"),
                            SmolStr::new_static("message")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("When the log entry was created"),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("jobId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("UUID of related job if applicable"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("level"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Log level")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("logType"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Type of log entry")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("message"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Log message")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("metadata"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("sliceUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("AT-URI of related slice if applicable"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("userDid"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("DID of related user if applicable"),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("jobId")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("jobId"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("UUID of the sync job"),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

fn _default_limit() -> Option<i64> {
    Some(100i64)
}

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

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

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

impl<S: BosStr> GetJobLogs<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetJobLogsBuilder<get_job_logs_state::Empty, S> {
        GetJobLogsBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> GetJobLogsBuilder<St, S>
where
    St: get_job_logs_state::State,
    St::JobId: get_job_logs_state::IsUnset,
{
    /// Set the `jobId` field (required)
    pub fn job_id(
        mut self,
        value: impl Into<S>,
    ) -> GetJobLogsBuilder<get_job_logs_state::SetJobId<St>, S> {
        self._fields.0 = Option::Some(value.into());
        GetJobLogsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> GetJobLogsBuilder<St, S>
where
    St: get_job_logs_state::State,
    St::JobId: get_job_logs_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetJobLogs<S> {
        GetJobLogs {
            job_id: self._fields.0.unwrap(),
            limit: self._fields.1,
        }
    }
}