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

//! Generated bindings for the `app.bsky.video` Lexicon namespace/module.
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, 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::blob::BlobRef;
use jacquard_common::types::string::Did;
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};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct JobStatus<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub blob: Option<BlobRef<S>>,
    pub did: Did<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<S>,
    pub job_id: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<S>,
    ///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.
    pub state: JobStatusState<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// 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<S: BosStr = DefaultStr> {
    JobStateCompleted,
    JobStateFailed,
    Other(S),
}

impl<S: BosStr> JobStatusState<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::JobStateCompleted => "JOB_STATE_COMPLETED",
            Self::JobStateFailed => "JOB_STATE_FAILED",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "JOB_STATE_COMPLETED" => Self::JobStateCompleted,
            "JOB_STATE_FAILED" => Self::JobStateFailed,
            _ => Self::Other(s),
        }
    }
}

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

impl<S: BosStr> AsRef<str> for JobStatusState<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for JobStatusState<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for JobStatusState<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for JobStatusState<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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

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

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

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

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

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

impl<St: job_status_state::State, S: BosStr> JobStatusBuilder<St, S> {
    /// Set the `blob` field (optional)
    pub fn blob(mut self, value: impl Into<Option<BlobRef<S>>>) -> 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<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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

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

impl<St: job_status_state::State, S: BosStr> JobStatusBuilder<St, 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<St, S: BosStr> JobStatusBuilder<St, S>
where
    St: job_status_state::State,
    St::State: job_status_state::IsUnset,
{
    /// Set the `state` field (required)
    pub fn state(
        mut self,
        value: impl Into<JobStatusState<S>>,
    ) -> JobStatusBuilder<job_status_state::SetState<St>, S> {
        self._fields.6 = Option::Some(value.into());
        JobStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> JobStatusBuilder<St, S>
where
    St: job_status_state::State,
    St::Did: job_status_state::IsSet,
    St::JobId: job_status_state::IsSet,
    St::State: job_status_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> JobStatus<S> {
        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<SmolStr, Data<S>>,
    ) -> JobStatus<S> {
        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()
    }
}