1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::common::CommonProperties;
5use crate::common::StixObject;
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "snake_case")]
10pub struct Sighting {
11 #[serde(flatten)]
12 pub common: CommonProperties,
13
14 pub count: u32,
15
16 pub sighting_of_ref: String,
17
18 pub where_sighted_refs: Vec<String>,
19}
20
21impl Sighting {
22 pub fn builder() -> crate::SightingBuilder {
23 crate::SightingBuilder::default()
24 }
25}
26
27impl StixObject for Sighting {
28 fn id(&self) -> &str {
29 &self.common.id
30 }
31 fn type_(&self) -> &str {
32 &self.common.r#type
33 }
34 fn created(&self) -> DateTime<Utc> {
35 self.common.created
36 }
37}
38
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
41#[serde(rename_all = "snake_case")]
42pub struct Relationship {
43 #[serde(flatten)]
44 pub common: CommonProperties,
45
46 pub source_ref: String,
47 pub target_ref: String,
48 pub relationship_type: String,
49}
50
51impl Relationship {
52 pub fn new(
53 source_ref: impl Into<String>,
54 target_ref: impl Into<String>,
55 relationship_type: impl Into<String>,
56 ) -> Self {
57 Self {
58 common: CommonProperties::new("relationship", None),
59 source_ref: source_ref.into(),
60 target_ref: target_ref.into(),
61 relationship_type: relationship_type.into(),
62 }
63 }
64}
65
66impl StixObject for Relationship {
67 fn id(&self) -> &str {
68 &self.common.id
69 }
70 fn type_(&self) -> &str {
71 &self.common.r#type
72 }
73 fn created(&self) -> DateTime<Utc> {
74 self.common.created
75 }
76}
77
78impl From<Relationship> for crate::StixObjectEnum {
79 fn from(r: Relationship) -> Self {
80 crate::StixObjectEnum::Relationship(r)
81 }
82}