1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use crate::deserializers::{coordinate_deserializer, rectangle_deserializer};
use df_st_core::{
    Coordinate, DeserializeBestEffort, DeserializeBestEffortTypes, Filler, HasUnknown, Rectangle,
};
use df_st_derive::{DeserializeBestEffort, HasUnknown, HashAndPartialEqById};
use indexmap::IndexMap;
use serde::{de, Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

#[derive(Serialize, Deserialize, Clone, Debug, Default, HasUnknown, HashAndPartialEqById)]
pub struct Site {
    pub id: i32,
    #[serde(alias = "type")]
    pub type_: Option<String>,
    pub name: Option<String>,
    #[serde(deserialize_with = "coordinate_deserializer")]
    #[serde(default)]
    pub coords: Option<Coordinate>,
    #[serde(deserialize_with = "rectangle_deserializer")]
    #[serde(default)]
    pub rectangle: Option<Rectangle>,
    pub structures: Option<Structures>,
    pub site_properties: Option<SiteProperties>,

    #[serde(flatten)]
    pub unknown: HashMap<String, Value>,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default, HasUnknown)]
pub struct Sites {
    pub site: Option<Vec<Site>>,

    #[serde(flatten)]
    pub unknown: HashMap<String, Value>,
}

#[derive(Serialize, DeserializeBestEffort, Clone, Debug, Default, HasUnknown)]
pub struct Structure {
    pub local_id: i32,
    #[serde(alias = "type")]
    pub type_: Option<String>,
    pub subtype: Option<String>,
    pub name: Option<String>,
    pub entity_id: Option<i32>,
    pub worship_hfid: Option<i32>,
    pub copied_artifact_id: Option<Vec<i32>>,

    #[serde(flatten)]
    pub unknown: HashMap<String, Value>,
}

#[derive(Serialize, DeserializeBestEffort, Clone, Debug, Default, HasUnknown)]
pub struct Structures {
    pub structure: Option<Vec<Structure>>,

    #[serde(flatten)]
    pub unknown: HashMap<String, Value>,
}

#[derive(Serialize, DeserializeBestEffort, Clone, Debug, Default, HasUnknown)]
pub struct SiteProperty {
    /// Local_id
    pub id: i32,
    #[serde(alias = "type")]
    pub type_: Option<String>,
    pub structure_id: Option<i32>,
    pub owner_hfid: Option<i32>,

    #[serde(flatten)]
    pub unknown: HashMap<String, Value>,
}

#[derive(Serialize, DeserializeBestEffort, Clone, Debug, Default, HasUnknown)]
pub struct SiteProperties {
    pub site_property: Option<Vec<SiteProperty>>,

    #[serde(flatten)]
    pub unknown: HashMap<String, Value>,
}

impl Filler<df_st_core::Site, Site> for df_st_core::Site {
    fn add_missing_data(&mut self, source: &Site) {
        self.id.add_missing_data(&source.id);
        self.type_.add_missing_data(&source.type_);
        self.name.add_missing_data(&source.name);
        self.coord.add_missing_data(&source.coords);
        self.rectangle.add_missing_data(&source.rectangle);
        if let Some(structures) = &source.structures {
            self.structures.add_missing_data(&structures.structure);
        }
        if let Some(site_properties) = &source.site_properties {
            self.site_properties
                .add_missing_data(&site_properties.site_property);
        }
    }
}

impl Filler<df_st_core::Structure, Structure> for df_st_core::Structure {
    fn add_missing_data(&mut self, source: &Structure) {
        self.local_id.add_missing_data(&source.local_id);
        self.type_.add_missing_data(&source.type_);
        self.subtype.add_missing_data(&source.subtype);
        self.name.add_missing_data(&source.name);
        self.entity_id.add_missing_data(&source.entity_id);
        self.worship_hfid.add_missing_data(&source.worship_hfid);
        self.copied_artifact_id
            .add_missing_data(&source.copied_artifact_id);
    }
}

impl Filler<df_st_core::SiteProperty, SiteProperty> for df_st_core::SiteProperty {
    fn add_missing_data(&mut self, source: &SiteProperty) {
        self.local_id.add_missing_data(&source.id);
        self.type_.add_missing_data(&source.type_);
        self.structure_id.add_missing_data(&source.structure_id);
        self.owner_hfid.add_missing_data(&source.owner_hfid);
    }
}

impl PartialEq<df_st_core::Site> for Site {
    fn eq(&self, other: &df_st_core::Site) -> bool {
        self.id == other.id
    }
}

impl PartialEq<df_st_core::Structure> for Structure {
    fn eq(&self, other: &df_st_core::Structure) -> bool {
        self.local_id == other.local_id
    }
}

impl PartialEq<df_st_core::SiteProperty> for SiteProperty {
    fn eq(&self, other: &df_st_core::SiteProperty) -> bool {
        self.id == other.local_id
    }
}

impl Filler<Vec<df_st_core::Site>, Sites> for Vec<df_st_core::Site> {
    fn add_missing_data(&mut self, source: &Sites) {
        self.add_missing_data(&source.site);
    }
}

impl Filler<IndexMap<u64, df_st_core::Site>, Sites> for IndexMap<u64, df_st_core::Site> {
    fn add_missing_data(&mut self, source: &Sites) {
        self.add_missing_data(&source.site);
    }
}