use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct LLMObsPromptSDKDataAttributes {
#[serde(rename = "chat_template")]
pub chat_template: Option<Vec<crate::datadogV2::model::LLMObsPromptChatMessage>>,
#[deprecated]
#[serde(rename = "labels")]
pub labels: Option<Vec<String>>,
#[serde(rename = "prompt_id")]
pub prompt_id: Option<String>,
#[serde(rename = "prompt_version_uuid")]
pub prompt_version_uuid: Option<String>,
#[serde(rename = "template")]
pub template: Option<String>,
#[serde(rename = "version")]
pub version: Option<String>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}
impl LLMObsPromptSDKDataAttributes {
pub fn new() -> LLMObsPromptSDKDataAttributes {
#[allow(deprecated)]
LLMObsPromptSDKDataAttributes {
chat_template: None,
labels: None,
prompt_id: None,
prompt_version_uuid: None,
template: None,
version: None,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}
#[allow(deprecated)]
pub fn chat_template(
mut self,
value: Vec<crate::datadogV2::model::LLMObsPromptChatMessage>,
) -> Self {
self.chat_template = Some(value);
self
}
#[allow(deprecated)]
pub fn labels(mut self, value: Vec<String>) -> Self {
self.labels = Some(value);
self
}
#[allow(deprecated)]
pub fn prompt_id(mut self, value: String) -> Self {
self.prompt_id = Some(value);
self
}
#[allow(deprecated)]
pub fn prompt_version_uuid(mut self, value: String) -> Self {
self.prompt_version_uuid = Some(value);
self
}
#[allow(deprecated)]
pub fn template(mut self, value: String) -> Self {
self.template = Some(value);
self
}
#[allow(deprecated)]
pub fn version(mut self, value: String) -> Self {
self.version = Some(value);
self
}
pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}
impl Default for LLMObsPromptSDKDataAttributes {
fn default() -> Self {
Self::new()
}
}
impl<'de> Deserialize<'de> for LLMObsPromptSDKDataAttributes {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct LLMObsPromptSDKDataAttributesVisitor;
impl<'a> Visitor<'a> for LLMObsPromptSDKDataAttributesVisitor {
type Value = LLMObsPromptSDKDataAttributes;
fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
}
fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'a>,
{
let mut chat_template: Option<
Vec<crate::datadogV2::model::LLMObsPromptChatMessage>,
> = None;
let mut labels: Option<Vec<String>> = None;
let mut prompt_id: Option<String> = None;
let mut prompt_version_uuid: Option<String> = None;
let mut template: Option<String> = None;
let mut version: Option<String> = None;
let mut additional_properties: std::collections::BTreeMap<
String,
serde_json::Value,
> = std::collections::BTreeMap::new();
let mut _unparsed = false;
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"chat_template" => {
if v.is_null() {
continue;
}
chat_template =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"labels" => {
if v.is_null() {
continue;
}
labels = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"prompt_id" => {
if v.is_null() {
continue;
}
prompt_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"prompt_version_uuid" => {
if v.is_null() {
continue;
}
prompt_version_uuid =
Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"template" => {
if v.is_null() {
continue;
}
template = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
"version" => {
if v.is_null() {
continue;
}
version = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
}
&_ => {
if let Ok(value) = serde_json::from_value(v.clone()) {
additional_properties.insert(k, value);
}
}
}
}
#[allow(deprecated)]
let content = LLMObsPromptSDKDataAttributes {
chat_template,
labels,
prompt_id,
prompt_version_uuid,
template,
version,
additional_properties,
_unparsed,
};
Ok(content)
}
}
deserializer.deserialize_any(LLMObsPromptSDKDataAttributesVisitor)
}
}