use crate::value::ValueType;
use serde::Serialize;
#[derive(Clone, Copy, Debug, Serialize)]
pub struct ParamSchema {
pub name: &'static str,
pub value_type: ValueType,
pub required: bool,
pub description: &'static str,
pub example: &'static str,
}
#[derive(Clone, Copy, Debug, Serialize)]
pub struct PositionalSchema {
pub description: &'static str,
pub example: &'static str,
}
#[derive(Clone, Copy, Debug, Serialize)]
pub struct TargetRule {
pub key: &'static str,
pub required_yes: &'static [&'static str],
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum AnnotationKind {
Primary,
Modifier { of: &'static str },
}
#[derive(Clone, Copy, Debug, Serialize)]
pub struct AnnotationSchema {
pub name: &'static str,
pub kind: AnnotationKind,
pub description: &'static str,
pub params: &'static [ParamSchema],
pub positional: Option<PositionalSchema>,
pub target: Option<TargetRule>,
}
impl AnnotationSchema {
pub fn param(&self, name: &str) -> Option<&'static ParamSchema> {
self.params.iter().find(|param| param.name == name)
}
}
#[derive(Clone, Copy, Debug)]
pub struct Registry {
pub schemas: &'static [AnnotationSchema],
}
impl Registry {
pub fn get(&self, name: &str) -> Option<&'static AnnotationSchema> {
self.schemas.iter().find(|schema| schema.name == name)
}
}