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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, Datetime};
use jacquard_common::types::value::Data;
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::network_slices::slice::get_job_logs;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LogEntry<'a> {
    ///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")]
    #[serde(borrow)]
    pub job_id: Option<CowStr<'a>>,
    ///Log level
    #[serde(borrow)]
    pub level: CowStr<'a>,
    ///Type of log entry
    #[serde(borrow)]
    pub log_type: CowStr<'a>,
    ///Log message
    #[serde(borrow)]
    pub message: CowStr<'a>,
    ///Additional metadata associated with the log entry
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub metadata: Option<Data<'a>>,
    ///AT-URI of related slice if applicable
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub slice_uri: Option<CowStr<'a>>,
    ///DID of related user if applicable
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub user_did: Option<Did<'a>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetJobLogs<'a> {
    #[serde(borrow)]
    pub job_id: CowStr<'a>,
    ///Defaults to `100`. Min: 1. Max: 1000.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetJobLogsOutput<'a> {
    #[serde(borrow)]
    pub logs: Vec<get_job_logs::LogEntry<'a>>,
}

impl<'a> LexiconSchema for LogEntry<'a> {
    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 type for network.slices.slice.getJobLogs
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<'de> = GetJobLogsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Endpoint type for network.slices.slice.getJobLogs
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<'de> = GetJobLogs<'de>;
    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 Id;
        type CreatedAt;
        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 Id = Unset;
        type CreatedAt = Unset;
        type Level = Unset;
        type LogType = Unset;
        type Message = Unset;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetId<S> {}
    impl<S: State> State for SetId<S> {
        type Id = Set<members::id>;
        type CreatedAt = S::CreatedAt;
        type Level = S::Level;
        type LogType = S::LogType;
        type Message = S::Message;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Id = S::Id;
        type CreatedAt = Set<members::created_at>;
        type Level = S::Level;
        type LogType = S::LogType;
        type Message = S::Message;
    }
    ///State transition - sets the `level` field to Set
    pub struct SetLevel<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLevel<S> {}
    impl<S: State> State for SetLevel<S> {
        type Id = S::Id;
        type CreatedAt = S::CreatedAt;
        type Level = Set<members::level>;
        type LogType = S::LogType;
        type Message = S::Message;
    }
    ///State transition - sets the `log_type` field to Set
    pub struct SetLogType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLogType<S> {}
    impl<S: State> State for SetLogType<S> {
        type Id = S::Id;
        type CreatedAt = S::CreatedAt;
        type Level = S::Level;
        type LogType = Set<members::log_type>;
        type Message = S::Message;
    }
    ///State transition - sets the `message` field to Set
    pub struct SetMessage<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMessage<S> {}
    impl<S: State> State for SetMessage<S> {
        type Id = S::Id;
        type CreatedAt = S::CreatedAt;
        type Level = S::Level;
        type LogType = S::LogType;
        type Message = Set<members::message>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///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<'a, S: log_entry_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Datetime>,
        Option<i64>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<Data<'a>>,
        Option<CowStr<'a>>,
        Option<Did<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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

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

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

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

impl<'a, S: log_entry_state::State> LogEntryBuilder<'a, S> {
    /// Set the `userDid` field (optional)
    pub fn user_did(mut self, value: impl Into<Option<Did<'a>>>) -> 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<'a>>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<'a, S> LogEntryBuilder<'a, S>
where
    S: log_entry_state::State,
    S::Id: log_entry_state::IsSet,
    S::CreatedAt: log_entry_state::IsSet,
    S::Level: log_entry_state::IsSet,
    S::LogType: log_entry_state::IsSet,
    S::Message: log_entry_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> LogEntry<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> LogEntry<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetJobId<S> {}
    impl<S: State> State for SetJobId<S> {
        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<'a, S: get_job_logs_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<i64>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: get_job_logs_state::State> GetJobLogsBuilder<'a, 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<'a, S> GetJobLogsBuilder<'a, S>
where
    S: get_job_logs_state::State,
    S::JobId: get_job_logs_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetJobLogs<'a> {
        GetJobLogs {
            job_id: self._fields.0.unwrap(),
            limit: self._fields.1,
        }
    }
}