use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct CellApi {
pub cell: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<HashMap<String, ApiType>>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub commands: HashMap<String, ApiCommand>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub events: HashMap<String, ApiEvent>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Eq)]
pub struct ApiType {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub fields: Vec<ApiField>,
}
impl ApiType {
pub fn find_field(&self, name: &str) -> Option<&ApiField> {
self.fields.iter().find(|f| f.name == name)
}
}
impl PartialEq for ApiType {
fn eq(&self, other: &Self) -> bool {
self.fields == other.fields
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiField {
pub name: String,
#[serde(default)]
pub serde_with: Option<String>,
#[serde(rename = "type")]
pub field_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
}
impl PartialEq for ApiField {
fn eq(&self, other: &Self) -> bool {
self.name == other.name && self.field_type == other.field_type
}
}
impl Eq for ApiField {}
#[derive(Debug, Serialize, Deserialize)]
pub struct ApiEvent(pub ApiType);
impl AsRef<ApiType> for ApiEvent {
fn as_ref(&self) -> &ApiType {
&self.0
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ApiCommand {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub args: Option<String>,
}