// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: space.polymodel.library.stageFile
//
// 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};
use jacquard_common::deps::bytes::Bytes;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::space_polymodel::library::File;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct StageFile {
    pub body: Bytes,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct StageFileOutput<S: BosStr = DefaultStr> {
    pub file: File<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filename: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<StageFileOutputStatus<S>>,
    pub upload_id: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StageFileOutputStatus<S: BosStr = DefaultStr> {
    Uploaded,
    Other(S),
}

impl<S: BosStr> StageFileOutputStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Uploaded => "uploaded",
            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() {
            "uploaded" => Self::Uploaded,
            _ => Self::Other(s),
        }
    }
}

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

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

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

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

/** Response marker for the `space.polymodel.library.stageFile` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `StageFileOutput<S>` for this endpoint.*/
pub struct StageFileResponse;
impl jacquard_common::xrpc::XrpcResp for StageFileResponse {
    const NSID: &'static str = "space.polymodel.library.stageFile";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = StageFileOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl jacquard_common::xrpc::XrpcRequest for StageFile {
    const NSID: &'static str = "space.polymodel.library.stageFile";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "*/*",
    );
    type Response = StageFileResponse;
    fn encode_body(
        &self,
        buffer: &mut Vec<u8>,
    ) -> Result<(), jacquard_common::xrpc::EncodeError>
    where
        Self: Serialize,
    {
        Ok(buffer.extend_from_slice(self.body.as_ref()))
    }
    fn decode_body<'de>(
        body: &'de [u8],
    ) -> Result<Self, jacquard_common::error::DecodeError>
    where
        Self: Deserialize<'de>,
    {
        Ok(Self {
            body: jacquard_common::deps::bytes::Bytes::copy_from_slice(body),
        })
    }
}

/** Endpoint marker for the `space.polymodel.library.stageFile` procedure.

Path: `/xrpc/space.polymodel.library.stageFile`. The request payload type is `StageFile`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct StageFileRequest;
impl jacquard_common::xrpc::XrpcEndpoint for StageFileRequest {
    const PATH: &'static str = "/xrpc/space.polymodel.library.stageFile";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "*/*",
    );
    type Request<S: BosStr> = StageFile;
    type Response = StageFileResponse;
}