use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GPParameter {
String(GPString),
Long(GPLong),
Double(GPDouble),
Boolean(GPBoolean),
Date(GPDate),
LinearUnit(GPLinearUnit),
FeatureRecordSetLayer(GPFeatureRecordSetLayer),
RasterDataLayer(GPRasterDataLayer),
DataFile(GPDataFile),
Raw(Value),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct GPString(pub String);
impl From<String> for GPString {
fn from(s: String) -> Self {
GPString(s)
}
}
impl From<&str> for GPString {
fn from(s: &str) -> Self {
GPString(s.to_string())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct GPLong(pub i64);
impl From<i64> for GPLong {
fn from(i: i64) -> Self {
GPLong(i)
}
}
impl From<i32> for GPLong {
fn from(i: i32) -> Self {
GPLong(i as i64)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct GPDouble(pub f64);
impl From<f64> for GPDouble {
fn from(f: f64) -> Self {
GPDouble(f)
}
}
impl From<f32> for GPDouble {
fn from(f: f32) -> Self {
GPDouble(f as f64)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct GPBoolean(pub bool);
impl From<bool> for GPBoolean {
fn from(b: bool) -> Self {
GPBoolean(b)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct GPDate(pub i64);
impl GPDate {
pub fn from_millis(millis: i64) -> Self {
GPDate(millis)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GPLinearUnit {
pub distance: f64,
pub units: String,
}
impl GPLinearUnit {
pub fn new(distance: f64, units: impl Into<String>) -> Self {
GPLinearUnit {
distance,
units: units.into(),
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GPFeatureRecordSetLayer {
pub geometry_type: String,
pub features: Vec<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub spatial_reference: Option<Value>,
}
impl GPFeatureRecordSetLayer {
pub fn new(geometry_type: impl Into<String>, features: Vec<Value>) -> Self {
GPFeatureRecordSetLayer {
geometry_type: geometry_type.into(),
features,
spatial_reference: None,
}
}
pub fn with_spatial_reference(mut self, sr: Value) -> Self {
self.spatial_reference = Some(sr);
self
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GPRasterDataLayer {
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<String>,
}
impl GPRasterDataLayer {
pub fn new(url: impl Into<String>) -> Self {
GPRasterDataLayer {
url: url.into(),
format: None,
}
}
pub fn with_format(mut self, format: impl Into<String>) -> Self {
self.format = Some(format.into());
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GPDataFile {
pub url: String,
}
impl GPDataFile {
pub fn new(url: impl Into<String>) -> Self {
GPDataFile { url: url.into() }
}
}