#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsAssignmentActivity {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub previous_status: Option<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsAssignmentActivity {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.previous_status.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.previous_status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("previousStatus")?;
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.previous_status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("previousStatus", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_previous_status: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"previousStatus" => {
if let crate::cbor::Value::Text(s) = value {
field_previous_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsAssignmentActivity {
previous_status: field_previous_status,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsAssignmentView {
pub did: crate::syntax::Did,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub end_at: Option<crate::syntax::Datetime>,
pub id: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub moderator: Option<crate::api::tools::ozone::TeamDefsMember>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub queue: Option<crate::api::tools::ozone::QueueDefsQueueView>,
pub report_id: i64,
pub start_at: crate::syntax::Datetime,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsAssignmentView {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 4u64;
if self.end_at.is_some() {
count += 1;
}
if self.queue.is_some() {
count += 1;
}
if self.moderator.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("id")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("did")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.did.as_str())?;
if self.end_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("endAt")?;
if let Some(ref val) = self.end_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.queue.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("queue")?;
if let Some(ref val) = self.queue {
val.encode_cbor(buf)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("startAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.start_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("reportId")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.report_id)?;
if self.moderator.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("moderator")?;
if let Some(ref val) = self.moderator {
val.encode_cbor(buf)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.id)?;
pairs.push(("id", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.did.as_str())?;
pairs.push(("did", vbuf));
}
if self.end_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.end_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("endAt", vbuf));
}
if self.queue.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.queue {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("queue", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.start_at.as_str())?;
pairs.push(("startAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.report_id)?;
pairs.push(("reportId", vbuf));
}
if self.moderator.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.moderator {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("moderator", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_id: Option<i64> = None;
let mut field_did: Option<crate::syntax::Did> = None;
let mut field_end_at: Option<crate::syntax::Datetime> = None;
let mut field_queue: Option<crate::api::tools::ozone::QueueDefsQueueView> = None;
let mut field_start_at: Option<crate::syntax::Datetime> = None;
let mut field_report_id: Option<i64> = None;
let mut field_moderator: Option<crate::api::tools::ozone::TeamDefsMember> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"id" => match value {
crate::cbor::Value::Unsigned(n) => {
field_id = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_id = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"did" => {
if let crate::cbor::Value::Text(s) = value {
field_did = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"endAt" => {
if let crate::cbor::Value::Text(s) = value {
field_end_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"queue" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_queue = Some(crate::api::tools::ozone::QueueDefsQueueView::decode_cbor(
&mut dec,
)?);
}
"startAt" => {
if let crate::cbor::Value::Text(s) = value {
field_start_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"reportId" => match value {
crate::cbor::Value::Unsigned(n) => {
field_report_id = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_report_id = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"moderator" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_moderator = Some(crate::api::tools::ozone::TeamDefsMember::decode_cbor(
&mut dec,
)?);
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsAssignmentView {
id: field_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'id'".into())
})?,
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
end_at: field_end_at,
queue: field_queue,
start_at: field_start_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'startAt'".into())
})?,
report_id: field_report_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'reportId'".into())
})?,
moderator: field_moderator,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsCloseActivity {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub previous_status: Option<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsCloseActivity {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.previous_status.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.previous_status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("previousStatus")?;
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.previous_status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("previousStatus", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_previous_status: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"previousStatus" => {
if let crate::cbor::Value::Text(s) = value {
field_previous_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsCloseActivity {
previous_status: field_previous_status,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsEscalationActivity {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub previous_status: Option<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsEscalationActivity {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.previous_status.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.previous_status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("previousStatus")?;
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.previous_status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("previousStatus", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_previous_status: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"previousStatus" => {
if let crate::cbor::Value::Text(s) = value {
field_previous_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsEscalationActivity {
previous_status: field_previous_status,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsHistoricalStats {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub action_rate: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub actioned_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avg_handling_time_sec: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub computed_at: Option<crate::syntax::Datetime>,
pub date: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub escalated_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub inbound_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pending_count: Option<i64>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsHistoricalStats {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 1u64;
if self.action_rate.is_some() {
count += 1;
}
if self.computed_at.is_some() {
count += 1;
}
if self.inbound_count.is_some() {
count += 1;
}
if self.pending_count.is_some() {
count += 1;
}
if self.actioned_count.is_some() {
count += 1;
}
if self.escalated_count.is_some() {
count += 1;
}
if self.avg_handling_time_sec.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("date")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.date)?;
if self.action_rate.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actionRate")?;
if let Some(ref val) = self.action_rate {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.computed_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("computedAt")?;
if let Some(ref val) = self.computed_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.inbound_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("inboundCount")?;
if let Some(ref val) = self.inbound_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.pending_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("pendingCount")?;
if let Some(ref val) = self.pending_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.actioned_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actionedCount")?;
if let Some(ref val) = self.actioned_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.escalated_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("escalatedCount")?;
if let Some(ref val) = self.escalated_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.avg_handling_time_sec.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("avgHandlingTimeSec")?;
if let Some(ref val) = self.avg_handling_time_sec {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.date)?;
pairs.push(("date", vbuf));
}
if self.action_rate.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.action_rate {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("actionRate", vbuf));
}
if self.computed_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.computed_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("computedAt", vbuf));
}
if self.inbound_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.inbound_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("inboundCount", vbuf));
}
if self.pending_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.pending_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("pendingCount", vbuf));
}
if self.actioned_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.actioned_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("actionedCount", vbuf));
}
if self.escalated_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.escalated_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("escalatedCount", vbuf));
}
if self.avg_handling_time_sec.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.avg_handling_time_sec {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("avgHandlingTimeSec", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_date: Option<String> = None;
let mut field_action_rate: Option<i64> = None;
let mut field_computed_at: Option<crate::syntax::Datetime> = None;
let mut field_inbound_count: Option<i64> = None;
let mut field_pending_count: Option<i64> = None;
let mut field_actioned_count: Option<i64> = None;
let mut field_escalated_count: Option<i64> = None;
let mut field_avg_handling_time_sec: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"date" => {
if let crate::cbor::Value::Text(s) = value {
field_date = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actionRate" => match value {
crate::cbor::Value::Unsigned(n) => {
field_action_rate = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_action_rate = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"computedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_computed_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"inboundCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_inbound_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_inbound_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"pendingCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_pending_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_pending_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"actionedCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_actioned_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_actioned_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"escalatedCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_escalated_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_escalated_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"avgHandlingTimeSec" => match value {
crate::cbor::Value::Unsigned(n) => {
field_avg_handling_time_sec = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_avg_handling_time_sec = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsHistoricalStats {
date: field_date.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'date'".into())
})?,
action_rate: field_action_rate,
computed_at: field_computed_at,
inbound_count: field_inbound_count,
pending_count: field_pending_count,
actioned_count: field_actioned_count,
escalated_count: field_escalated_count,
avg_handling_time_sec: field_avg_handling_time_sec,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsLiveStats {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub action_rate: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub actioned_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avg_handling_time_sec: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub escalated_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub inbound_count: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub last_updated: Option<crate::syntax::Datetime>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pending_count: Option<i64>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsLiveStats {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.action_rate.is_some() {
count += 1;
}
if self.last_updated.is_some() {
count += 1;
}
if self.inbound_count.is_some() {
count += 1;
}
if self.pending_count.is_some() {
count += 1;
}
if self.actioned_count.is_some() {
count += 1;
}
if self.escalated_count.is_some() {
count += 1;
}
if self.avg_handling_time_sec.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.action_rate.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actionRate")?;
if let Some(ref val) = self.action_rate {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.last_updated.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("lastUpdated")?;
if let Some(ref val) = self.last_updated {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.inbound_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("inboundCount")?;
if let Some(ref val) = self.inbound_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.pending_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("pendingCount")?;
if let Some(ref val) = self.pending_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.actioned_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actionedCount")?;
if let Some(ref val) = self.actioned_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.escalated_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("escalatedCount")?;
if let Some(ref val) = self.escalated_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
if self.avg_handling_time_sec.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("avgHandlingTimeSec")?;
if let Some(ref val) = self.avg_handling_time_sec {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.action_rate.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.action_rate {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("actionRate", vbuf));
}
if self.last_updated.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.last_updated {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("lastUpdated", vbuf));
}
if self.inbound_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.inbound_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("inboundCount", vbuf));
}
if self.pending_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.pending_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("pendingCount", vbuf));
}
if self.actioned_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.actioned_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("actionedCount", vbuf));
}
if self.escalated_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.escalated_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("escalatedCount", vbuf));
}
if self.avg_handling_time_sec.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.avg_handling_time_sec {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("avgHandlingTimeSec", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_action_rate: Option<i64> = None;
let mut field_last_updated: Option<crate::syntax::Datetime> = None;
let mut field_inbound_count: Option<i64> = None;
let mut field_pending_count: Option<i64> = None;
let mut field_actioned_count: Option<i64> = None;
let mut field_escalated_count: Option<i64> = None;
let mut field_avg_handling_time_sec: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"actionRate" => match value {
crate::cbor::Value::Unsigned(n) => {
field_action_rate = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_action_rate = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"lastUpdated" => {
if let crate::cbor::Value::Text(s) = value {
field_last_updated = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"inboundCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_inbound_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_inbound_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"pendingCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_pending_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_pending_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"actionedCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_actioned_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_actioned_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"escalatedCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_escalated_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_escalated_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"avgHandlingTimeSec" => match value {
crate::cbor::Value::Unsigned(n) => {
field_avg_handling_time_sec = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_avg_handling_time_sec = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsLiveStats {
action_rate: field_action_rate,
last_updated: field_last_updated,
inbound_count: field_inbound_count,
pending_count: field_pending_count,
actioned_count: field_actioned_count,
escalated_count: field_escalated_count,
avg_handling_time_sec: field_avg_handling_time_sec,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsNoteActivity {
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsNoteActivity {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let count = 0u64;
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsNoteActivity {
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsQueueActivity {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub previous_status: Option<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsQueueActivity {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.previous_status.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.previous_status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("previousStatus")?;
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.previous_status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("previousStatus", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_previous_status: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"previousStatus" => {
if let crate::cbor::Value::Text(s) = value {
field_previous_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsQueueActivity {
previous_status: field_previous_status,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
pub const REPORT_DEFS_REASON_APPEAL: &str = "tools.ozone.report.defs#reasonAppeal";
pub const REPORT_DEFS_REASON_CHILD_SAFETY_C_S_A_M: &str =
"tools.ozone.report.defs#reasonChildSafetyCSAM";
pub const REPORT_DEFS_REASON_CHILD_SAFETY_GROOM: &str =
"tools.ozone.report.defs#reasonChildSafetyGroom";
pub const REPORT_DEFS_REASON_CHILD_SAFETY_HARASSMENT: &str =
"tools.ozone.report.defs#reasonChildSafetyHarassment";
pub const REPORT_DEFS_REASON_CHILD_SAFETY_OTHER: &str =
"tools.ozone.report.defs#reasonChildSafetyOther";
pub const REPORT_DEFS_REASON_CHILD_SAFETY_PRIVACY: &str =
"tools.ozone.report.defs#reasonChildSafetyPrivacy";
pub const REPORT_DEFS_REASON_HARASSMENT_DOXXING: &str =
"tools.ozone.report.defs#reasonHarassmentDoxxing";
pub const REPORT_DEFS_REASON_HARASSMENT_HATE_SPEECH: &str =
"tools.ozone.report.defs#reasonHarassmentHateSpeech";
pub const REPORT_DEFS_REASON_HARASSMENT_OTHER: &str =
"tools.ozone.report.defs#reasonHarassmentOther";
pub const REPORT_DEFS_REASON_HARASSMENT_TARGETED: &str =
"tools.ozone.report.defs#reasonHarassmentTargeted";
pub const REPORT_DEFS_REASON_HARASSMENT_TROLL: &str =
"tools.ozone.report.defs#reasonHarassmentTroll";
pub const REPORT_DEFS_REASON_MISLEADING_BOT: &str = "tools.ozone.report.defs#reasonMisleadingBot";
pub const REPORT_DEFS_REASON_MISLEADING_ELECTIONS: &str =
"tools.ozone.report.defs#reasonMisleadingElections";
pub const REPORT_DEFS_REASON_MISLEADING_IMPERSONATION: &str =
"tools.ozone.report.defs#reasonMisleadingImpersonation";
pub const REPORT_DEFS_REASON_MISLEADING_OTHER: &str =
"tools.ozone.report.defs#reasonMisleadingOther";
pub const REPORT_DEFS_REASON_MISLEADING_SCAM: &str = "tools.ozone.report.defs#reasonMisleadingScam";
pub const REPORT_DEFS_REASON_MISLEADING_SPAM: &str = "tools.ozone.report.defs#reasonMisleadingSpam";
pub const REPORT_DEFS_REASON_OTHER: &str = "tools.ozone.report.defs#reasonOther";
pub const REPORT_DEFS_REASON_RULE_BAN_EVASION: &str =
"tools.ozone.report.defs#reasonRuleBanEvasion";
pub const REPORT_DEFS_REASON_RULE_OTHER: &str = "tools.ozone.report.defs#reasonRuleOther";
pub const REPORT_DEFS_REASON_RULE_PROHIBITED_SALES: &str =
"tools.ozone.report.defs#reasonRuleProhibitedSales";
pub const REPORT_DEFS_REASON_RULE_SITE_SECURITY: &str =
"tools.ozone.report.defs#reasonRuleSiteSecurity";
pub const REPORT_DEFS_REASON_SELF_HARM_CONTENT: &str =
"tools.ozone.report.defs#reasonSelfHarmContent";
pub const REPORT_DEFS_REASON_SELF_HARM_E_D: &str = "tools.ozone.report.defs#reasonSelfHarmED";
pub const REPORT_DEFS_REASON_SELF_HARM_OTHER: &str = "tools.ozone.report.defs#reasonSelfHarmOther";
pub const REPORT_DEFS_REASON_SELF_HARM_STUNTS: &str =
"tools.ozone.report.defs#reasonSelfHarmStunts";
pub const REPORT_DEFS_REASON_SELF_HARM_SUBSTANCES: &str =
"tools.ozone.report.defs#reasonSelfHarmSubstances";
pub const REPORT_DEFS_REASON_SEXUAL_ABUSE_CONTENT: &str =
"tools.ozone.report.defs#reasonSexualAbuseContent";
pub const REPORT_DEFS_REASON_SEXUAL_ANIMAL: &str = "tools.ozone.report.defs#reasonSexualAnimal";
pub const REPORT_DEFS_REASON_SEXUAL_DEEPFAKE: &str = "tools.ozone.report.defs#reasonSexualDeepfake";
pub const REPORT_DEFS_REASON_SEXUAL_N_C_I_I: &str = "tools.ozone.report.defs#reasonSexualNCII";
pub const REPORT_DEFS_REASON_SEXUAL_OTHER: &str = "tools.ozone.report.defs#reasonSexualOther";
pub const REPORT_DEFS_REASON_SEXUAL_UNLABELED: &str =
"tools.ozone.report.defs#reasonSexualUnlabeled";
pub type ReportDefsReasonType = String;
pub const REPORT_DEFS_REASON_VIOLENCE_ANIMAL: &str = "tools.ozone.report.defs#reasonViolenceAnimal";
pub const REPORT_DEFS_REASON_VIOLENCE_EXTREMIST_CONTENT: &str =
"tools.ozone.report.defs#reasonViolenceExtremistContent";
pub const REPORT_DEFS_REASON_VIOLENCE_GLORIFICATION: &str =
"tools.ozone.report.defs#reasonViolenceGlorification";
pub const REPORT_DEFS_REASON_VIOLENCE_GRAPHIC_CONTENT: &str =
"tools.ozone.report.defs#reasonViolenceGraphicContent";
pub const REPORT_DEFS_REASON_VIOLENCE_OTHER: &str = "tools.ozone.report.defs#reasonViolenceOther";
pub const REPORT_DEFS_REASON_VIOLENCE_THREATS: &str =
"tools.ozone.report.defs#reasonViolenceThreats";
pub const REPORT_DEFS_REASON_VIOLENCE_TRAFFICKING: &str =
"tools.ozone.report.defs#reasonViolenceTrafficking";
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsReopenActivity {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub previous_status: Option<String>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsReopenActivity {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 0u64;
if self.previous_status.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
if self.previous_status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("previousStatus")?;
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
if self.previous_status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.previous_status {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("previousStatus", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_previous_status: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"previousStatus" => {
if let crate::cbor::Value::Text(s) = value {
field_previous_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsReopenActivity {
previous_status: field_previous_status,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsReportActivityView {
pub activity: ReportDefsReportActivityViewActivityUnion,
pub created_at: crate::syntax::Datetime,
pub created_by: crate::syntax::Did,
pub id: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub internal_note: Option<String>,
pub is_automated: bool,
pub meta: serde_json::Value,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub moderator: Option<crate::api::tools::ozone::TeamDefsMember>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub public_note: Option<String>,
pub report_id: i64,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
#[derive(Debug, Clone)]
pub enum ReportDefsReportActivityViewActivityUnion {
ReportDefsQueueActivity(Box<ReportDefsQueueActivity>),
ReportDefsAssignmentActivity(Box<ReportDefsAssignmentActivity>),
ReportDefsEscalationActivity(Box<ReportDefsEscalationActivity>),
ReportDefsCloseActivity(Box<ReportDefsCloseActivity>),
ReportDefsReopenActivity(Box<ReportDefsReopenActivity>),
ReportDefsNoteActivity(Box<ReportDefsNoteActivity>),
Unknown(crate::api::UnknownUnionVariant),
}
impl serde::Serialize for ReportDefsReportActivityViewActivityUnion {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
ReportDefsReportActivityViewActivityUnion::ReportDefsQueueActivity(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"tools.ozone.report.defs#queueActivity".to_string(),
),
);
}
map.serialize(serializer)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsAssignmentActivity(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"tools.ozone.report.defs#assignmentActivity".to_string(),
),
);
}
map.serialize(serializer)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsEscalationActivity(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"tools.ozone.report.defs#escalationActivity".to_string(),
),
);
}
map.serialize(serializer)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsCloseActivity(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"tools.ozone.report.defs#closeActivity".to_string(),
),
);
}
map.serialize(serializer)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsReopenActivity(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"tools.ozone.report.defs#reopenActivity".to_string(),
),
);
}
map.serialize(serializer)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsNoteActivity(inner) => {
let mut map =
serde_json::to_value(inner.as_ref()).map_err(serde::ser::Error::custom)?;
if let serde_json::Value::Object(ref mut m) = map {
m.insert(
"$type".to_string(),
serde_json::Value::String(
"tools.ozone.report.defs#noteActivity".to_string(),
),
);
}
map.serialize(serializer)
}
ReportDefsReportActivityViewActivityUnion::Unknown(v) => {
if let Some(ref j) = v.json {
j.serialize(serializer)
} else {
Err(serde::ser::Error::custom(
"no JSON data for unknown union variant",
))
}
}
}
}
}
impl<'de> serde::Deserialize<'de> for ReportDefsReportActivityViewActivityUnion {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let value = serde_json::Value::deserialize(deserializer)?;
let type_str = value
.get("$type")
.and_then(|v| v.as_str())
.unwrap_or_default();
match type_str {
"tools.ozone.report.defs#queueActivity" => {
let inner: ReportDefsQueueActivity =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsQueueActivity(Box::new(
inner,
)),
)
}
"tools.ozone.report.defs#assignmentActivity" => {
let inner: ReportDefsAssignmentActivity =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsAssignmentActivity(
Box::new(inner),
),
)
}
"tools.ozone.report.defs#escalationActivity" => {
let inner: ReportDefsEscalationActivity =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsEscalationActivity(
Box::new(inner),
),
)
}
"tools.ozone.report.defs#closeActivity" => {
let inner: ReportDefsCloseActivity =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsCloseActivity(Box::new(
inner,
)),
)
}
"tools.ozone.report.defs#reopenActivity" => {
let inner: ReportDefsReopenActivity =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsReopenActivity(Box::new(
inner,
)),
)
}
"tools.ozone.report.defs#noteActivity" => {
let inner: ReportDefsNoteActivity =
serde_json::from_value(value).map_err(serde::de::Error::custom)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsNoteActivity(Box::new(
inner,
)),
)
}
_ => Ok(ReportDefsReportActivityViewActivityUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: Some(value),
cbor: None,
},
)),
}
}
}
impl ReportDefsReportActivityViewActivityUnion {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
match self {
ReportDefsReportActivityViewActivityUnion::ReportDefsQueueActivity(inner) => {
inner.encode_cbor(buf)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsAssignmentActivity(inner) => {
inner.encode_cbor(buf)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsEscalationActivity(inner) => {
inner.encode_cbor(buf)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsCloseActivity(inner) => {
inner.encode_cbor(buf)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsReopenActivity(inner) => {
inner.encode_cbor(buf)
}
ReportDefsReportActivityViewActivityUnion::ReportDefsNoteActivity(inner) => {
inner.encode_cbor(buf)
}
ReportDefsReportActivityViewActivityUnion::Unknown(v) => {
if let Some(ref data) = v.cbor {
buf.extend_from_slice(data);
Ok(())
} else {
Err(crate::cbor::CborError::InvalidCbor(
"no CBOR data for unknown union variant".into(),
))
}
}
}
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let start = decoder.position();
let val = decoder.decode()?;
let end = decoder.position();
let raw = &decoder.raw_input()[start..end];
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected map for union".into(),
));
}
};
let type_str = entries
.iter()
.find(|(k, _)| *k == "$type")
.and_then(|(_, v)| match v {
crate::cbor::Value::Text(s) => Some(*s),
_ => None,
})
.unwrap_or_default();
match type_str {
"tools.ozone.report.defs#queueActivity" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ReportDefsQueueActivity::decode_cbor(&mut dec)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsQueueActivity(Box::new(
inner,
)),
)
}
"tools.ozone.report.defs#assignmentActivity" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ReportDefsAssignmentActivity::decode_cbor(&mut dec)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsAssignmentActivity(
Box::new(inner),
),
)
}
"tools.ozone.report.defs#escalationActivity" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ReportDefsEscalationActivity::decode_cbor(&mut dec)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsEscalationActivity(
Box::new(inner),
),
)
}
"tools.ozone.report.defs#closeActivity" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ReportDefsCloseActivity::decode_cbor(&mut dec)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsCloseActivity(Box::new(
inner,
)),
)
}
"tools.ozone.report.defs#reopenActivity" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ReportDefsReopenActivity::decode_cbor(&mut dec)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsReopenActivity(Box::new(
inner,
)),
)
}
"tools.ozone.report.defs#noteActivity" => {
let mut dec = crate::cbor::Decoder::new(raw);
let inner = ReportDefsNoteActivity::decode_cbor(&mut dec)?;
Ok(
ReportDefsReportActivityViewActivityUnion::ReportDefsNoteActivity(Box::new(
inner,
)),
)
}
_ => Ok(ReportDefsReportActivityViewActivityUnion::Unknown(
crate::api::UnknownUnionVariant {
r#type: type_str.to_string(),
json: None,
cbor: Some(raw.to_vec()),
},
)),
}
}
}
impl ReportDefsReportActivityView {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 6u64;
if self.moderator.is_some() {
count += 1;
}
if self.public_note.is_some() {
count += 1;
}
if self.internal_note.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("id")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("activity")?;
self.activity.encode_cbor(buf)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("reportId")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.report_id)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.created_at.as_str())?;
crate::cbor::Encoder::new(&mut *buf).encode_text("createdBy")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.created_by.as_str())?;
if self.moderator.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("moderator")?;
if let Some(ref val) = self.moderator {
val.encode_cbor(buf)?;
}
}
if self.public_note.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("publicNote")?;
if let Some(ref val) = self.public_note {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("isAutomated")?;
crate::cbor::Encoder::new(&mut *buf).encode_bool(self.is_automated)?;
if self.internal_note.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("internalNote")?;
if let Some(ref val) = self.internal_note {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.id)?;
pairs.push(("id", vbuf));
}
{
let mut vbuf = Vec::new();
self.activity.encode_cbor(&mut vbuf)?;
pairs.push(("activity", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.report_id)?;
pairs.push(("reportId", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.created_at.as_str())?;
pairs.push(("createdAt", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.created_by.as_str())?;
pairs.push(("createdBy", vbuf));
}
if self.moderator.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.moderator {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("moderator", vbuf));
}
if self.public_note.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.public_note {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("publicNote", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_bool(self.is_automated)?;
pairs.push(("isAutomated", vbuf));
}
if self.internal_note.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.internal_note {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("internalNote", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_id: Option<i64> = None;
let mut field_activity: Option<ReportDefsReportActivityViewActivityUnion> = None;
let mut field_report_id: Option<i64> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_created_by: Option<crate::syntax::Did> = None;
let mut field_moderator: Option<crate::api::tools::ozone::TeamDefsMember> = None;
let mut field_public_note: Option<String> = None;
let mut field_is_automated: Option<bool> = None;
let mut field_internal_note: Option<String> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"id" => match value {
crate::cbor::Value::Unsigned(n) => {
field_id = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_id = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"activity" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_activity = Some(ReportDefsReportActivityViewActivityUnion::decode_cbor(
&mut dec,
)?);
}
"reportId" => match value {
crate::cbor::Value::Unsigned(n) => {
field_report_id = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_report_id = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"createdAt" => {
if let crate::cbor::Value::Text(s) = value {
field_created_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"createdBy" => {
if let crate::cbor::Value::Text(s) = value {
field_created_by = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"moderator" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_moderator = Some(crate::api::tools::ozone::TeamDefsMember::decode_cbor(
&mut dec,
)?);
}
"publicNote" => {
if let crate::cbor::Value::Text(s) = value {
field_public_note = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"isAutomated" => {
if let crate::cbor::Value::Bool(b) = value {
field_is_automated = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"internalNote" => {
if let crate::cbor::Value::Text(s) = value {
field_internal_note = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsReportActivityView {
id: field_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'id'".into())
})?,
meta: Default::default(),
activity: field_activity.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'activity'".into())
})?,
report_id: field_report_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'reportId'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
created_by: field_created_by.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdBy'".into())
})?,
moderator: field_moderator,
public_note: field_public_note,
is_automated: field_is_automated.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'isAutomated'".into())
})?,
internal_note: field_internal_note,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsReportAssignment {
pub assigned_at: crate::syntax::Datetime,
pub did: crate::syntax::Did,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub moderator: Option<crate::api::tools::ozone::TeamDefsMember>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsReportAssignment {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 2u64;
if self.moderator.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("did")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.did.as_str())?;
if self.moderator.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("moderator")?;
if let Some(ref val) = self.moderator {
val.encode_cbor(buf)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("assignedAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.assigned_at.as_str())?;
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.did.as_str())?;
pairs.push(("did", vbuf));
}
if self.moderator.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.moderator {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("moderator", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.assigned_at.as_str())?;
pairs.push(("assignedAt", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_did: Option<crate::syntax::Did> = None;
let mut field_moderator: Option<crate::api::tools::ozone::TeamDefsMember> = None;
let mut field_assigned_at: Option<crate::syntax::Datetime> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"did" => {
if let crate::cbor::Value::Text(s) = value {
field_did = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"moderator" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_moderator = Some(crate::api::tools::ozone::TeamDefsMember::decode_cbor(
&mut dec,
)?);
}
"assignedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_assigned_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsReportAssignment {
did: field_did.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'did'".into())
})?,
moderator: field_moderator,
assigned_at: field_assigned_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'assignedAt'".into())
})?,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReportDefsReportView {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub action_event_ids: Vec<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub action_note: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub actions: Vec<crate::api::tools::ozone::ModerationDefsModEventView>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub assignment: Option<ReportDefsReportAssignment>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub comment: Option<String>,
pub created_at: crate::syntax::Datetime,
pub event_id: i64,
pub id: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_muted: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub queue: Option<crate::api::tools::ozone::QueueDefsQueueView>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub queued_at: Option<crate::syntax::Datetime>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub related_report_count: Option<i64>,
pub report_type: crate::api::com::atproto::ModerationDefsReasonType,
pub reported_by: crate::syntax::Did,
pub reporter: crate::api::tools::ozone::ModerationDefsSubjectView,
pub status: String,
pub subject: crate::api::tools::ozone::ModerationDefsSubjectView,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub subject_status: Option<crate::api::tools::ozone::ModerationDefsSubjectStatusView>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub updated_at: Option<crate::syntax::Datetime>,
#[serde(flatten)]
pub extra: std::collections::HashMap<String, serde_json::Value>,
#[serde(skip)]
pub extra_cbor: Vec<(String, Vec<u8>)>,
}
impl ReportDefsReportView {
pub fn to_cbor(&self) -> Result<Vec<u8>, crate::cbor::CborError> {
let mut buf = Vec::new();
self.encode_cbor(&mut buf)?;
Ok(buf)
}
pub fn encode_cbor(&self, buf: &mut Vec<u8>) -> Result<(), crate::cbor::CborError> {
if self.extra_cbor.is_empty() {
let mut count = 8u64;
if self.queue.is_some() {
count += 1;
}
if !self.actions.is_empty() {
count += 1;
}
if self.comment.is_some() {
count += 1;
}
if self.is_muted.is_some() {
count += 1;
}
if self.queued_at.is_some() {
count += 1;
}
if self.updated_at.is_some() {
count += 1;
}
if self.action_note.is_some() {
count += 1;
}
if self.assignment.is_some() {
count += 1;
}
if self.subject_status.is_some() {
count += 1;
}
if !self.action_event_ids.is_empty() {
count += 1;
}
if self.related_report_count.is_some() {
count += 1;
}
crate::cbor::Encoder::new(&mut *buf).encode_map_header(count)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("id")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.id)?;
if self.queue.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("queue")?;
if let Some(ref val) = self.queue {
val.encode_cbor(buf)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("status")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.status)?;
if !self.actions.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actions")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.actions.len() as u64)?;
for item in &self.actions {
item.encode_cbor(buf)?;
}
}
if self.comment.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("comment")?;
if let Some(ref val) = self.comment {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("eventId")?;
crate::cbor::Encoder::new(&mut *buf).encode_i64(self.event_id)?;
if self.is_muted.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("isMuted")?;
if let Some(ref val) = self.is_muted {
crate::cbor::Encoder::new(&mut *buf).encode_bool(*val)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("subject")?;
self.subject.encode_cbor(buf)?;
if self.queued_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("queuedAt")?;
if let Some(ref val) = self.queued_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("reporter")?;
self.reporter.encode_cbor(buf)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("createdAt")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.created_at.as_str())?;
if self.updated_at.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("updatedAt")?;
if let Some(ref val) = self.updated_at {
crate::cbor::Encoder::new(&mut *buf).encode_text(val.as_str())?;
}
}
if self.action_note.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actionNote")?;
if let Some(ref val) = self.action_note {
crate::cbor::Encoder::new(&mut *buf).encode_text(val)?;
}
}
if self.assignment.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("assignment")?;
if let Some(ref val) = self.assignment {
val.encode_cbor(buf)?;
}
}
crate::cbor::Encoder::new(&mut *buf).encode_text("reportType")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(&self.report_type)?;
crate::cbor::Encoder::new(&mut *buf).encode_text("reportedBy")?;
crate::cbor::Encoder::new(&mut *buf).encode_text(self.reported_by.as_str())?;
if self.subject_status.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("subjectStatus")?;
if let Some(ref val) = self.subject_status {
val.encode_cbor(buf)?;
}
}
if !self.action_event_ids.is_empty() {
crate::cbor::Encoder::new(&mut *buf).encode_text("actionEventIds")?;
crate::cbor::Encoder::new(&mut *buf)
.encode_array_header(self.action_event_ids.len() as u64)?;
for item in &self.action_event_ids {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*item)?;
}
}
if self.related_report_count.is_some() {
crate::cbor::Encoder::new(&mut *buf).encode_text("relatedReportCount")?;
if let Some(ref val) = self.related_report_count {
crate::cbor::Encoder::new(&mut *buf).encode_i64(*val)?;
}
}
} else {
let mut pairs: Vec<(&str, Vec<u8>)> = Vec::new();
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.id)?;
pairs.push(("id", vbuf));
}
if self.queue.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.queue {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("queue", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.status)?;
pairs.push(("status", vbuf));
}
if !self.actions.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.actions.len() as u64)?;
for item in &self.actions {
item.encode_cbor(&mut vbuf)?;
}
pairs.push(("actions", vbuf));
}
if self.comment.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.comment {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("comment", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_i64(self.event_id)?;
pairs.push(("eventId", vbuf));
}
if self.is_muted.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.is_muted {
crate::cbor::Encoder::new(&mut vbuf).encode_bool(*val)?;
}
pairs.push(("isMuted", vbuf));
}
{
let mut vbuf = Vec::new();
self.subject.encode_cbor(&mut vbuf)?;
pairs.push(("subject", vbuf));
}
if self.queued_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.queued_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("queuedAt", vbuf));
}
{
let mut vbuf = Vec::new();
self.reporter.encode_cbor(&mut vbuf)?;
pairs.push(("reporter", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.created_at.as_str())?;
pairs.push(("createdAt", vbuf));
}
if self.updated_at.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.updated_at {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val.as_str())?;
}
pairs.push(("updatedAt", vbuf));
}
if self.action_note.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.action_note {
crate::cbor::Encoder::new(&mut vbuf).encode_text(val)?;
}
pairs.push(("actionNote", vbuf));
}
if self.assignment.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.assignment {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("assignment", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(&self.report_type)?;
pairs.push(("reportType", vbuf));
}
{
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf).encode_text(self.reported_by.as_str())?;
pairs.push(("reportedBy", vbuf));
}
if self.subject_status.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.subject_status {
val.encode_cbor(&mut vbuf)?;
}
pairs.push(("subjectStatus", vbuf));
}
if !self.action_event_ids.is_empty() {
let mut vbuf = Vec::new();
crate::cbor::Encoder::new(&mut vbuf)
.encode_array_header(self.action_event_ids.len() as u64)?;
for item in &self.action_event_ids {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*item)?;
}
pairs.push(("actionEventIds", vbuf));
}
if self.related_report_count.is_some() {
let mut vbuf = Vec::new();
if let Some(ref val) = self.related_report_count {
crate::cbor::Encoder::new(&mut vbuf).encode_i64(*val)?;
}
pairs.push(("relatedReportCount", vbuf));
}
for (k, v) in &self.extra_cbor {
pairs.push((k.as_str(), v.clone()));
}
pairs.sort_by(|a, b| crate::cbor::cbor_key_cmp(a.0, b.0));
crate::cbor::Encoder::new(&mut *buf).encode_map_header(pairs.len() as u64)?;
for (k, v) in &pairs {
crate::cbor::Encoder::new(&mut *buf).encode_text(k)?;
buf.extend_from_slice(v);
}
}
Ok(())
}
pub fn from_cbor(data: &[u8]) -> Result<Self, crate::cbor::CborError> {
let mut decoder = crate::cbor::Decoder::new(data);
let result = Self::decode_cbor(&mut decoder)?;
if !decoder.is_empty() {
return Err(crate::cbor::CborError::InvalidCbor("trailing data".into()));
}
Ok(result)
}
pub fn decode_cbor(decoder: &mut crate::cbor::Decoder) -> Result<Self, crate::cbor::CborError> {
let val = decoder.decode()?;
let entries = match val {
crate::cbor::Value::Map(entries) => entries,
_ => return Err(crate::cbor::CborError::InvalidCbor("expected map".into())),
};
let mut field_id: Option<i64> = None;
let mut field_queue: Option<crate::api::tools::ozone::QueueDefsQueueView> = None;
let mut field_status: Option<String> = None;
let mut field_actions: Vec<crate::api::tools::ozone::ModerationDefsModEventView> =
Vec::new();
let mut field_comment: Option<String> = None;
let mut field_event_id: Option<i64> = None;
let mut field_is_muted: Option<bool> = None;
let mut field_subject: Option<crate::api::tools::ozone::ModerationDefsSubjectView> = None;
let mut field_queued_at: Option<crate::syntax::Datetime> = None;
let mut field_reporter: Option<crate::api::tools::ozone::ModerationDefsSubjectView> = None;
let mut field_created_at: Option<crate::syntax::Datetime> = None;
let mut field_updated_at: Option<crate::syntax::Datetime> = None;
let mut field_action_note: Option<String> = None;
let mut field_assignment: Option<ReportDefsReportAssignment> = None;
let mut field_report_type: Option<crate::api::com::atproto::ModerationDefsReasonType> =
None;
let mut field_reported_by: Option<crate::syntax::Did> = None;
let mut field_subject_status: Option<
crate::api::tools::ozone::ModerationDefsSubjectStatusView,
> = None;
let mut field_action_event_ids: Vec<i64> = Vec::new();
let mut field_related_report_count: Option<i64> = None;
let mut extra_cbor: Vec<(String, Vec<u8>)> = Vec::new();
for (key, value) in entries {
match key {
"id" => match value {
crate::cbor::Value::Unsigned(n) => {
field_id = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_id = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"queue" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_queue = Some(crate::api::tools::ozone::QueueDefsQueueView::decode_cbor(
&mut dec,
)?);
}
"status" => {
if let crate::cbor::Value::Text(s) = value {
field_status = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actions" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
let raw = crate::cbor::encode_value(&item)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_actions.push(
crate::api::tools::ozone::ModerationDefsModEventView::decode_cbor(
&mut dec,
)?,
);
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"comment" => {
if let crate::cbor::Value::Text(s) = value {
field_comment = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"eventId" => match value {
crate::cbor::Value::Unsigned(n) => {
field_event_id = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_event_id = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
"isMuted" => {
if let crate::cbor::Value::Bool(b) = value {
field_is_muted = Some(b);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected bool".into()));
}
}
"subject" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_subject = Some(
crate::api::tools::ozone::ModerationDefsSubjectView::decode_cbor(&mut dec)?,
);
}
"queuedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_queued_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"reporter" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_reporter = Some(
crate::api::tools::ozone::ModerationDefsSubjectView::decode_cbor(&mut dec)?,
);
}
"createdAt" => {
if let crate::cbor::Value::Text(s) = value {
field_created_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"updatedAt" => {
if let crate::cbor::Value::Text(s) = value {
field_updated_at = Some(
crate::syntax::Datetime::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"actionNote" => {
if let crate::cbor::Value::Text(s) = value {
field_action_note = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"assignment" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_assignment = Some(ReportDefsReportAssignment::decode_cbor(&mut dec)?);
}
"reportType" => {
if let crate::cbor::Value::Text(s) = value {
field_report_type = Some(s.to_string());
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"reportedBy" => {
if let crate::cbor::Value::Text(s) = value {
field_reported_by = Some(
crate::syntax::Did::try_from(s)
.map_err(|e| crate::cbor::CborError::InvalidCbor(e.to_string()))?,
);
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected text".into()));
}
}
"subjectStatus" => {
let raw = crate::cbor::encode_value(&value)?;
let mut dec = crate::cbor::Decoder::new(&raw);
field_subject_status = Some(
crate::api::tools::ozone::ModerationDefsSubjectStatusView::decode_cbor(
&mut dec,
)?,
);
}
"actionEventIds" => {
if let crate::cbor::Value::Array(items) = value {
for item in items {
match item {
crate::cbor::Value::Unsigned(n) => {
field_action_event_ids.push(n as i64)
}
crate::cbor::Value::Signed(n) => field_action_event_ids.push(n),
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer in array".into(),
));
}
}
}
} else {
return Err(crate::cbor::CborError::InvalidCbor("expected array".into()));
}
}
"relatedReportCount" => match value {
crate::cbor::Value::Unsigned(n) => {
field_related_report_count = Some(n as i64);
}
crate::cbor::Value::Signed(n) => {
field_related_report_count = Some(n);
}
_ => {
return Err(crate::cbor::CborError::InvalidCbor(
"expected integer".into(),
));
}
},
_ => {
let raw = crate::cbor::encode_value(&value)?;
extra_cbor.push((key.to_string(), raw));
}
}
}
Ok(ReportDefsReportView {
id: field_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'id'".into())
})?,
queue: field_queue,
status: field_status.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'status'".into())
})?,
actions: field_actions,
comment: field_comment,
event_id: field_event_id.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'eventId'".into())
})?,
is_muted: field_is_muted,
subject: field_subject.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'subject'".into())
})?,
queued_at: field_queued_at,
reporter: field_reporter.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'reporter'".into())
})?,
created_at: field_created_at.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'createdAt'".into())
})?,
updated_at: field_updated_at,
action_note: field_action_note,
assignment: field_assignment,
report_type: field_report_type.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'reportType'".into())
})?,
reported_by: field_reported_by.ok_or_else(|| {
crate::cbor::CborError::InvalidCbor("missing required field 'reportedBy'".into())
})?,
subject_status: field_subject_status,
action_event_ids: field_action_event_ids,
related_report_count: field_related_report_count,
extra: std::collections::HashMap::new(),
extra_cbor,
})
}
}