// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: place.stream.media.getUploadStatus
//
// 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::AtUri;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
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::place_stream::media::get_upload_status;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetUploadStatus<S: BosStr = DefaultStr> {
    pub upload_id: S,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetUploadStatusOutput<S: BosStr = DefaultStr> {
    ///Duration of the processed video in milliseconds. Present when status is 'done'.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration_ms: Option<i64>,
    ///Error message. Present when status is 'error'.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error: Option<S>,
    ///Processing progress percentage (0-100). Only meaningful when status is 'processing'.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub progress: Option<i64>,
    ///Current processing status of the upload.
    pub status: GetUploadStatusOutputStatus<S>,
    ///Published track records. Present when status is 'done'.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tracks: Option<Vec<get_upload_status::TrackRef<S>>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Current processing status of the upload.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GetUploadStatusOutputStatus<S: BosStr = DefaultStr> {
    Pending,
    Processing,
    Done,
    Error,
    Other(S),
}

impl<S: BosStr> GetUploadStatusOutputStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Pending => "pending",
            Self::Processing => "processing",
            Self::Done => "done",
            Self::Error => "error",
            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() {
            "pending" => Self::Pending,
            "processing" => Self::Processing,
            "done" => Self::Done,
            "error" => Self::Error,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for GetUploadStatusOutputStatus<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 GetUploadStatusOutputStatus<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 GetUploadStatusOutputStatus<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for GetUploadStatusOutputStatus<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = GetUploadStatusOutputStatus<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            GetUploadStatusOutputStatus::Pending => GetUploadStatusOutputStatus::Pending,
            GetUploadStatusOutputStatus::Processing => {
                GetUploadStatusOutputStatus::Processing
            }
            GetUploadStatusOutputStatus::Done => GetUploadStatusOutputStatus::Done,
            GetUploadStatusOutputStatus::Error => GetUploadStatusOutputStatus::Error,
            GetUploadStatusOutputStatus::Other(v) => {
                GetUploadStatusOutputStatus::Other(v.into_static())
            }
        }
    }
}


#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic
)]

#[serde(tag = "error", content = "message")]
pub enum GetUploadStatusError {
    /// No upload exists with the given ID for the authenticated user.
    #[serde(rename = "NotFound")]
    NotFound(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for GetUploadStatusError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::NotFound(msg) => {
                write!(f, "NotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}


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

/** Response marker for the `place.stream.media.getUploadStatus` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetUploadStatusOutput<S>` for this endpoint.*/
pub struct GetUploadStatusResponse;
impl jacquard_common::xrpc::XrpcResp for GetUploadStatusResponse {
    const NSID: &'static str = "place.stream.media.getUploadStatus";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetUploadStatusOutput<S>;
    type Err = GetUploadStatusError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetUploadStatus<S> {
    const NSID: &'static str = "place.stream.media.getUploadStatus";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetUploadStatusResponse;
}

/** Endpoint marker for the `place.stream.media.getUploadStatus` query.

Path: `/xrpc/place.stream.media.getUploadStatus`. The request payload type is `GetUploadStatus<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetUploadStatusRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetUploadStatusRequest {
    const PATH: &'static str = "/xrpc/place.stream.media.getUploadStatus";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetUploadStatus<S>;
    type Response = GetUploadStatusResponse;
}

impl<S: BosStr> LexiconSchema for TrackRef<S> {
    fn nsid() -> &'static str {
        "place.stream.media.getUploadStatus"
    }
    fn def_name() -> &'static str {
        "trackRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_media_getUploadStatus()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> GetUploadStatus<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetUploadStatusBuilder<get_upload_status_state::Empty, S> {
        GetUploadStatusBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> GetUploadStatusBuilder<St, S>
where
    St: get_upload_status_state::State,
    St::UploadId: get_upload_status_state::IsUnset,
{
    /// Set the `uploadId` field (required)
    pub fn upload_id(
        mut self,
        value: impl Into<S>,
    ) -> GetUploadStatusBuilder<get_upload_status_state::SetUploadId<St>, S> {
        self._fields.0 = Option::Some(value.into());
        GetUploadStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GetUploadStatusBuilder<St, S>
where
    St: get_upload_status_state::State,
    St::UploadId: get_upload_status_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetUploadStatus<S> {
        GetUploadStatus {
            upload_id: self._fields.0.unwrap(),
        }
    }
}

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

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

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

impl<S: BosStr> TrackRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> TrackRefBuilder<track_ref_state::Empty, S> {
        TrackRefBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> TrackRefBuilder<St, S>
where
    St: track_ref_state::State,
    St::Cid: track_ref_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<S>,
    ) -> TrackRefBuilder<track_ref_state::SetCid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        TrackRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TrackRefBuilder<St, S>
where
    St: track_ref_state::State,
    St::Uri: track_ref_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> TrackRefBuilder<track_ref_state::SetUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        TrackRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TrackRefBuilder<St, S>
where
    St: track_ref_state::State,
    St::Cid: track_ref_state::IsSet,
    St::Uri: track_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> TrackRef<S> {
        TrackRef {
            cid: self._fields.0.unwrap(),
            uri: 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<SmolStr, Data<S>>) -> TrackRef<S> {
        TrackRef {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_place_stream_media_getUploadStatus() -> 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("place.stream.media.getUploadStatus"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("uploadId")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("uploadId"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "The upload ID returned by place.stream.media.createUpload.",
                                            ),
                                        ),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("trackRef"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("uri"), SmolStr::new_static("cid")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}