// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: io.atcr.hold.getPartUploadUrl
//
// 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;
use jacquard_common::types::string::UriValue;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetPartUploadUrl<'a> {
    ///Part sequence number (1-indexed)
    pub part_number: i64,
    ///Upload session ID from initiateUpload
    #[serde(borrow)]
    pub upload_id: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetPartUploadUrlOutput<'a> {
    ///Additional headers required for the request (e.g., content-type)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub headers: Option<Data<'a>>,
    ///HTTP method to use (usually PUT)  Defaults to `"PUT"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_get_part_upload_url_output_method")]
    #[serde(borrow)]
    pub method: Option<CowStr<'a>>,
    ///URL to PUT the part data to
    #[serde(borrow)]
    pub url: UriValue<'a>,
}


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

#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum GetPartUploadUrlError<'a> {
    #[serde(rename = "InvalidUploadId")]
    InvalidUploadId(Option<CowStr<'a>>),
    #[serde(rename = "InvalidPartNumber")]
    InvalidPartNumber(Option<CowStr<'a>>),
}

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

/// Response type for io.atcr.hold.getPartUploadUrl
pub struct GetPartUploadUrlResponse;
impl jacquard_common::xrpc::XrpcResp for GetPartUploadUrlResponse {
    const NSID: &'static str = "io.atcr.hold.getPartUploadUrl";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetPartUploadUrlOutput<'de>;
    type Err<'de> = GetPartUploadUrlError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetPartUploadUrl<'a> {
    const NSID: &'static str = "io.atcr.hold.getPartUploadUrl";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = GetPartUploadUrlResponse;
}

/// Endpoint type for io.atcr.hold.getPartUploadUrl
pub struct GetPartUploadUrlRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetPartUploadUrlRequest {
    const PATH: &'static str = "/xrpc/io.atcr.hold.getPartUploadUrl";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = GetPartUploadUrl<'de>;
    type Response = GetPartUploadUrlResponse;
}

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

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

impl<'a> GetPartUploadUrl<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetPartUploadUrlBuilder<'a, get_part_upload_url_state::Empty> {
        GetPartUploadUrlBuilder::new()
    }
}

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

impl<'a, S> GetPartUploadUrlBuilder<'a, S>
where
    S: get_part_upload_url_state::State,
    S::PartNumber: get_part_upload_url_state::IsUnset,
{
    /// Set the `partNumber` field (required)
    pub fn part_number(
        mut self,
        value: impl Into<i64>,
    ) -> GetPartUploadUrlBuilder<'a, get_part_upload_url_state::SetPartNumber<S>> {
        self._fields.0 = Option::Some(value.into());
        GetPartUploadUrlBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> GetPartUploadUrlBuilder<'a, S>
where
    S: get_part_upload_url_state::State,
    S::UploadId: get_part_upload_url_state::IsUnset,
{
    /// Set the `uploadId` field (required)
    pub fn upload_id(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> GetPartUploadUrlBuilder<'a, get_part_upload_url_state::SetUploadId<S>> {
        self._fields.1 = Option::Some(value.into());
        GetPartUploadUrlBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> GetPartUploadUrlBuilder<'a, S>
where
    S: get_part_upload_url_state::State,
    S::PartNumber: get_part_upload_url_state::IsSet,
    S::UploadId: get_part_upload_url_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetPartUploadUrl<'a> {
        GetPartUploadUrl {
            part_number: self._fields.0.unwrap(),
            upload_id: 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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> GetPartUploadUrl<'a> {
        GetPartUploadUrl {
            part_number: self._fields.0.unwrap(),
            upload_id: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn _default_get_part_upload_url_output_method() -> Option<CowStr<'static>> {
    Some(CowStr::from("PUT"))
}