// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.server.getConfig
//
// 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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, UriValue};
use jacquard_derive::{IntoStatic, lexicon};
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::tools_ozone::server::get_config;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetConfigOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub appview: Option<get_config::ServiceConfig<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub blob_divert: Option<get_config::ServiceConfig<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub chat: Option<get_config::ServiceConfig<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub pds: Option<get_config::ServiceConfig<'a>>,
    ///The did of the verifier used for verification.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub verifier_did: Option<Did<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub viewer: Option<get_config::ViewerConfig<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ServiceConfig<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub url: Option<UriValue<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ViewerConfig<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub role: Option<ViewerConfigRole<'a>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ViewerConfigRole<'a> {
    RoleAdmin,
    RoleModerator,
    RoleTriage,
    RoleVerifier,
    Other(CowStr<'a>),
}

impl<'a> ViewerConfigRole<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::RoleAdmin => "tools.ozone.team.defs#roleAdmin",
            Self::RoleModerator => "tools.ozone.team.defs#roleModerator",
            Self::RoleTriage => "tools.ozone.team.defs#roleTriage",
            Self::RoleVerifier => "tools.ozone.team.defs#roleVerifier",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for ViewerConfigRole<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "tools.ozone.team.defs#roleAdmin" => Self::RoleAdmin,
            "tools.ozone.team.defs#roleModerator" => Self::RoleModerator,
            "tools.ozone.team.defs#roleTriage" => Self::RoleTriage,
            "tools.ozone.team.defs#roleVerifier" => Self::RoleVerifier,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ViewerConfigRole<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "tools.ozone.team.defs#roleAdmin" => Self::RoleAdmin,
            "tools.ozone.team.defs#roleModerator" => Self::RoleModerator,
            "tools.ozone.team.defs#roleTriage" => Self::RoleTriage,
            "tools.ozone.team.defs#roleVerifier" => Self::RoleVerifier,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for ViewerConfigRole<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> serde::Serialize for ViewerConfigRole<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for ViewerConfigRole<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for ViewerConfigRole<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for ViewerConfigRole<'_> {
    type Output = ViewerConfigRole<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            ViewerConfigRole::RoleAdmin => ViewerConfigRole::RoleAdmin,
            ViewerConfigRole::RoleModerator => ViewerConfigRole::RoleModerator,
            ViewerConfigRole::RoleTriage => ViewerConfigRole::RoleTriage,
            ViewerConfigRole::RoleVerifier => ViewerConfigRole::RoleVerifier,
            ViewerConfigRole::Other(v) => ViewerConfigRole::Other(v.into_static()),
        }
    }
}

/// XRPC request marker type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Copy)]
pub struct GetConfig;
/// Response type for tools.ozone.server.getConfig
pub struct GetConfigResponse;
impl jacquard_common::xrpc::XrpcResp for GetConfigResponse {
    const NSID: &'static str = "tools.ozone.server.getConfig";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetConfigOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl jacquard_common::xrpc::XrpcRequest for GetConfig {
    const NSID: &'static str = "tools.ozone.server.getConfig";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetConfigResponse;
}

/// Endpoint type for tools.ozone.server.getConfig
pub struct GetConfigRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetConfigRequest {
    const PATH: &'static str = "/xrpc/tools.ozone.server.getConfig";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetConfig;
    type Response = GetConfigResponse;
}

impl<'a> LexiconSchema for ServiceConfig<'a> {
    fn nsid() -> &'static str {
        "tools.ozone.server.getConfig"
    }
    fn def_name() -> &'static str {
        "serviceConfig"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_server_getConfig()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for ViewerConfig<'a> {
    fn nsid() -> &'static str {
        "tools.ozone.server.getConfig"
    }
    fn def_name() -> &'static str {
        "viewerConfig"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_server_getConfig()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_tools_ozone_server_getConfig() -> 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("tools.ozone.server.getConfig"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: None,
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("serviceConfig"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("viewerConfig"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("role"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}