// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.communication.updateTemplate
//
// 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::{Did, Language};
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
use crate::tools_ozone::communication::TemplateView;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct UpdateTemplate<'a> {
    ///Content of the template, markdown supported, can contain variable placeholders.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub content_markdown: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disabled: Option<bool>,
    ///ID of the template to be updated.
    #[serde(borrow)]
    pub id: CowStr<'a>,
    ///Message language.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lang: Option<Language>,
    ///Name of the template.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub name: Option<CowStr<'a>>,
    ///Subject of the message, used in emails.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub subject: Option<CowStr<'a>>,
    ///DID of the user who is updating the template.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub updated_by: Option<Did<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct UpdateTemplateOutput<'a> {
    #[serde(flatten)]
    #[serde(borrow)]
    pub value: TemplateView<'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 UpdateTemplateError<'a> {
    #[serde(rename = "DuplicateTemplateName")]
    DuplicateTemplateName(Option<CowStr<'a>>),
}

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

/// Response type for tools.ozone.communication.updateTemplate
pub struct UpdateTemplateResponse;
impl jacquard_common::xrpc::XrpcResp for UpdateTemplateResponse {
    const NSID: &'static str = "tools.ozone.communication.updateTemplate";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = UpdateTemplateOutput<'de>;
    type Err<'de> = UpdateTemplateError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for UpdateTemplate<'a> {
    const NSID: &'static str = "tools.ozone.communication.updateTemplate";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = UpdateTemplateResponse;
}

/// Endpoint type for tools.ozone.communication.updateTemplate
pub struct UpdateTemplateRequest;
impl jacquard_common::xrpc::XrpcEndpoint for UpdateTemplateRequest {
    const PATH: &'static str = "/xrpc/tools.ozone.communication.updateTemplate";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = UpdateTemplate<'de>;
    type Response = UpdateTemplateResponse;
}