//! 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>,
}