use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TabularDataResource {
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<PathOrPaths>,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<Vec<serde_json::Value>>,
pub schema: TableSchema,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub homepage: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sources: Option<Vec<Source>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub licenses: Option<Vec<License>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dialect: Option<Dialect>,
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mediatype: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub encoding: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bytes: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hash: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum PathOrPaths {
Single(String),
Multiple(Vec<String>),
}
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TableSchema {
pub fields: Vec<TableSchemaField>,
#[serde(skip_serializing_if = "Option::is_none")]
pub primary_key: Option<PrimaryKey>,
#[serde(skip_serializing_if = "Option::is_none")]
pub foreign_keys: Option<Vec<ForeignKey>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub missing_values: Option<Vec<String>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase", untagged)]
pub enum PrimaryKey {
Single(String),
Multiple(Vec<String>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ForeignKey {
pub fields: ForeignKeyFields,
pub reference: ForeignKeyReference,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged)]
pub enum ForeignKeyFields {
Single(String),
Multiple(Vec<String>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ForeignKeyReference {
pub resource: String,
pub fields: ForeignKeyFields,
}
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct TableSchemaField {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub example: Option<String>,
#[serde(rename = "type")]
pub field_type: FieldType,
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<FieldFormat>,
#[serde(skip_serializing_if = "Option::is_none")]
pub constraints: Option<HashMap<String, serde_json::Value>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rdf_type: Option<String>,
}
#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum FieldType {
String,
Number,
Integer,
Date,
Time,
Datetime,
Year,
Yearmonth,
Boolean,
Object,
Geopoint,
Geojson,
Array,
Duration,
#[default]
Any,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum FieldFormat {
Default,
Email,
Uri,
Binary,
Uuid,
Any,
Array,
Object,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Source {
pub title: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct License {
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Dialect {
#[serde(skip_serializing_if = "Option::is_none")]
pub delimiter: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub double_quote: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub line_terminator: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub null_sequence: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub quote_char: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub escape_char: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub skip_initial_space: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub header: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub comment_char: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub case_sensitive_header: Option<bool>,
}