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
//! All area entities: `Shading`, `Hydrology` and `SoilTexture`

use chrono::NaiveDate;
use diesel::{AsChangeset, Identifiable, Insertable, Queryable};
use postgis_diesel::types::{Point, Polygon};
use uuid::Uuid;

use crate::{
    model::r#enum::{
        shade::Shade, soil_texture::SoilTextureEnum, water_requirement::WaterRequirementEnum,
    },
    schema::{hydrologies, shadings, soil_textures},
};

/// The `Shading` entity.
#[derive(Debug, Clone, Identifiable, Queryable, Insertable)]
#[diesel(table_name = shadings)]
pub struct Shading {
    /// The id of the shading.
    pub id: Uuid,
    /// The plant layer the shadings is on.
    pub layer_id: Uuid,
    /// The type/strength of shade.
    pub shade: Shade,
    /// The position of the shade on the map.
    pub geometry: Polygon<Point>,
    /// The date the shading was added to the map.
    /// If None, the shading always existed.
    pub add_date: Option<NaiveDate>,
    /// The date the shading was removed from the map.
    /// If None, the shading is still on the map.
    pub remove_date: Option<NaiveDate>,
    /// Markdown notes
    pub notes: String,
}

/// The `UpdateShading` entity.
#[derive(Debug, Clone, Default, AsChangeset)]
#[diesel(table_name = shadings)]
pub struct UpdateShading {
    pub id: Uuid,
    pub shade: Option<Shade>,
    pub geometry: Option<Polygon<Point>>,
    pub add_date: Option<Option<NaiveDate>>,
    pub remove_date: Option<Option<NaiveDate>>,
    pub notes: Option<String>,
}

/// The `Hydrology` entity.
#[derive(Debug, Clone, Identifiable, Queryable, Insertable)]
#[diesel(table_name = hydrologies)]
pub struct Hydrology {
    /// The id of the hydrology.
    pub id: Uuid,
    /// The plant layer the hydrology is on.
    pub layer_id: Uuid,
    /// The water requirement.
    pub water_requirement: WaterRequirementEnum,
    /// The position of the hydrology on the map.
    pub geometry: Polygon<Point>,
    /// The date the hydrology was added to the map.
    /// If None, the hydrology always existed.
    pub add_date: Option<NaiveDate>,
    /// The date the hydrology was removed from the map.
    /// If None, the hydrology is still on the map.
    pub remove_date: Option<NaiveDate>,
    /// Markdown notes
    pub notes: String,
}

/// The `UpdateHydrology` entity.
#[derive(Debug, Clone, Default, AsChangeset)]
#[diesel(table_name = hydrologies)]
pub struct UpdateHydrology {
    pub id: Uuid,
    pub water_requirement: Option<WaterRequirementEnum>,
    pub geometry: Option<Polygon<Point>>,
    pub add_date: Option<Option<NaiveDate>>,
    pub remove_date: Option<Option<NaiveDate>>,
    pub notes: Option<String>,
}

/// The `SoilTexture` entity.
#[derive(Debug, Clone, Identifiable, Queryable, Insertable)]
#[diesel(table_name = soil_textures)]
pub struct SoilTexture {
    /// The id of the shading.
    pub id: Uuid,
    /// The plant layer the shadings is on.
    pub layer_id: Uuid,
    /// The kind of soil texture.
    pub soil_texture: SoilTextureEnum,
    /// The position of the shade on the map.
    pub geometry: Polygon<Point>,
    /// The date the shading was added to the map.
    /// If None, the shading always existed.
    pub add_date: Option<NaiveDate>,
    /// The date the shading was removed from the map.
    /// If None, the shading is still on the map.
    pub remove_date: Option<NaiveDate>,
    /// Markdown notes
    pub notes: String,
}

/// Used to update the `SoilTexture` entity.
#[derive(Debug, Clone, Default, AsChangeset)]
#[diesel(table_name = soil_textures)]
pub struct UpdateSoilTexture {
    pub id: Uuid,
    pub soil_texture: Option<SoilTextureEnum>,
    pub geometry: Option<Polygon<Point>>,
    pub add_date: Option<Option<NaiveDate>>,
    pub remove_date: Option<Option<NaiveDate>>,
    pub notes: Option<String>,
}