// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.video.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

pub mod get_job_status;
pub mod get_upload_limits;
pub mod upload_video;


#[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::blob::BlobRef;
use jacquard_common::types::string::Did;
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 JobStatus<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub blob: Option<BlobRef<'a>>,
    #[serde(borrow)]
    pub did: Did<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub error: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub job_id: CowStr<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub message: Option<CowStr<'a>>,
    ///Progress within the current processing state.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub progress: Option<i64>,
    ///The state of the video processing job. All values not listed as a known value indicate that the job is in process.
    #[serde(borrow)]
    pub state: JobStatusState<'a>,
}

/// The state of the video processing job. All values not listed as a known value indicate that the job is in process.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum JobStatusState<'a> {
    JobStateCompleted,
    JobStateFailed,
    Other(CowStr<'a>),
}

impl<'a> JobStatusState<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::JobStateCompleted => "JOB_STATE_COMPLETED",
            Self::JobStateFailed => "JOB_STATE_FAILED",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for JobStatusState<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "JOB_STATE_COMPLETED" => Self::JobStateCompleted,
            "JOB_STATE_FAILED" => Self::JobStateFailed,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for JobStatusState<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "JOB_STATE_COMPLETED" => Self::JobStateCompleted,
            "JOB_STATE_FAILED" => Self::JobStateFailed,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> core::fmt::Display for JobStatusState<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> AsRef<str> for JobStatusState<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for JobStatusState<'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 JobStatusState<'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 JobStatusState<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for JobStatusState<'_> {
    type Output = JobStatusState<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            JobStatusState::JobStateCompleted => JobStatusState::JobStateCompleted,
            JobStatusState::JobStateFailed => JobStatusState::JobStateFailed,
            JobStatusState::Other(v) => JobStatusState::Other(v.into_static()),
        }
    }
}

impl<'a> LexiconSchema for JobStatus<'a> {
    fn nsid() -> &'static str {
        "app.bsky.video.defs"
    }
    fn def_name() -> &'static str {
        "jobStatus"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_video_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.progress {
            if *value > 100i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("progress"),
                    max: 100i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.progress {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("progress"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

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

/// Builder for constructing an instance of this type
pub struct JobStatusBuilder<'a, S: job_status_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<BlobRef<'a>>,
        Option<Did<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<i64>,
        Option<JobStatusState<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> JobStatus<'a> {
    /// Create a new builder for this type
    pub fn new() -> JobStatusBuilder<'a, job_status_state::Empty> {
        JobStatusBuilder::new()
    }
}

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

impl<'a, S: job_status_state::State> JobStatusBuilder<'a, S> {
    /// Set the `blob` field (optional)
    pub fn blob(mut self, value: impl Into<Option<BlobRef<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `blob` field to an Option value (optional)
    pub fn maybe_blob(mut self, value: Option<BlobRef<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> JobStatusBuilder<'a, S>
where
    S: job_status_state::State,
    S::Did: job_status_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> JobStatusBuilder<'a, job_status_state::SetDid<S>> {
        self._fields.1 = Option::Some(value.into());
        JobStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: job_status_state::State> JobStatusBuilder<'a, S> {
    /// Set the `error` field (optional)
    pub fn error(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `error` field to an Option value (optional)
    pub fn maybe_error(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<'a, S: job_status_state::State> JobStatusBuilder<'a, S> {
    /// Set the `message` field (optional)
    pub fn message(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `message` field to an Option value (optional)
    pub fn maybe_message(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S: job_status_state::State> JobStatusBuilder<'a, S> {
    /// Set the `progress` field (optional)
    pub fn progress(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `progress` field to an Option value (optional)
    pub fn maybe_progress(mut self, value: Option<i64>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S> JobStatusBuilder<'a, S>
where
    S: job_status_state::State,
    S::State: job_status_state::IsUnset,
{
    /// Set the `state` field (required)
    pub fn state(
        mut self,
        value: impl Into<JobStatusState<'a>>,
    ) -> JobStatusBuilder<'a, job_status_state::SetState<S>> {
        self._fields.6 = Option::Some(value.into());
        JobStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> JobStatusBuilder<'a, S>
where
    S: job_status_state::State,
    S::JobId: job_status_state::IsSet,
    S::Did: job_status_state::IsSet,
    S::State: job_status_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> JobStatus<'a> {
        JobStatus {
            blob: self._fields.0,
            did: self._fields.1.unwrap(),
            error: self._fields.2,
            job_id: self._fields.3.unwrap(),
            message: self._fields.4,
            progress: self._fields.5,
            state: self._fields.6.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>,
        >,
    ) -> JobStatus<'a> {
        JobStatus {
            blob: self._fields.0,
            did: self._fields.1.unwrap(),
            error: self._fields.2,
            job_id: self._fields.3.unwrap(),
            message: self._fields.4,
            progress: self._fields.5,
            state: self._fields.6.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_video_defs() -> 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("app.bsky.video.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("jobStatus"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("jobId"), SmolStr::new_static("did"),
                            SmolStr::new_static("state")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("blob"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("error"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("jobId"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("message"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("progress"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(100i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("state"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The state of the video processing job. All values not listed as a known value indicate that the job is in process.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}