Skip to main content

nil_core/report/
mod.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4pub mod battle;
5pub mod support;
6
7use crate::round::RoundId;
8use battle::BattleReport;
9use jiff::Zoned;
10use serde::{Deserialize, Serialize};
11use std::sync::Arc;
12use support::SupportReport;
13use uuid::Uuid;
14
15pub trait Report {
16  fn id(&self) -> ReportId;
17  fn round(&self) -> RoundId;
18  fn time(&self) -> &Zoned;
19}
20
21#[derive(Clone, Debug, Deserialize, Serialize)]
22#[serde(tag = "kind", rename_all = "kebab-case")]
23#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
24#[remain::sorted]
25pub enum ReportKind {
26  Battle { report: Arc<BattleReport> },
27  Support { report: Arc<SupportReport> },
28}
29
30impl ReportKind {
31  pub fn as_dyn(&self) -> &dyn Report {
32    match self {
33      Self::Battle { report } => report.as_ref(),
34      Self::Support { report } => report.as_ref(),
35    }
36  }
37
38  #[inline]
39  pub fn id(&self) -> ReportId {
40    self.as_dyn().id()
41  }
42}
43
44#[must_use]
45#[derive(
46  Clone,
47  Copy,
48  Debug,
49  derive_more::Display,
50  PartialEq,
51  Eq,
52  PartialOrd,
53  Ord,
54  Hash,
55  Deserialize,
56  Serialize,
57)]
58#[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
59pub struct ReportId(Uuid);
60
61impl ReportId {
62  #[inline]
63  pub fn new() -> Self {
64    Self(Uuid::now_v7())
65  }
66}
67
68impl Default for ReportId {
69  fn default() -> Self {
70    Self::new()
71  }
72}