// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.communication.createTemplate
//
// 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 CreateTemplate<'a> {
    ///Content of the template, markdown supported, can contain variable placeholders.
    #[serde(borrow)]
    pub content_markdown: CowStr<'a>,
    ///DID of the user who is creating the template.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub created_by: Option<Did<'a>>,
    ///Message language.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lang: Option<Language>,
    ///Name of the template.
    #[serde(borrow)]
    pub name: CowStr<'a>,
    ///Subject of the message, used in emails.
    #[serde(borrow)]
    pub subject: CowStr<'a>,
}


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

impl core::fmt::Display for CreateTemplateError<'_> {
    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.createTemplate
pub struct CreateTemplateResponse;
impl jacquard_common::xrpc::XrpcResp for CreateTemplateResponse {
    const NSID: &'static str = "tools.ozone.communication.createTemplate";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = CreateTemplateOutput<'de>;
    type Err<'de> = CreateTemplateError<'de>;
}

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

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