ryo-app 0.1.0

[preview] Application layer for RYO - Project management, Intent handling, API
Documentation
//! SpecFlow response types for API/CLI consumption.

use serde::{Deserialize, Serialize};

/// SpecFlow query result.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpecShowResponse {
    /// All groups with their specs.
    pub groups: Vec<SpecGroupInfo>,
    /// All dependency relations.
    pub relations: Vec<SpecRelation>,
    /// Statistics.
    pub stats: SpecStats,
}

/// Information about a spec group.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpecGroupInfo {
    /// Group name.
    pub name: String,
    /// Specs in this group.
    pub specs: Vec<SpecInfo>,
}

/// Information about a single spec alias.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpecInfo {
    /// Alias name (e.g., "DbConfig").
    pub alias_name: String,
    /// Wrapped type name (e.g., "DatabaseConfig").
    pub wrapped_type_name: String,
    /// Source of this spec.
    pub source: SpecSourceKind,
}

/// Source of spec information.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SpecSourceKind {
    /// From `type X = Spec<G, T>` (strict, compile-time).
    TypeAlias,
    /// From `@spec:group(G)` comment (flexible, advisory).
    Comment,
    /// Inferred by analysis.
    Inferred,
}

/// Dependency relation between specs.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpecRelation {
    /// Source spec name.
    pub from: String,
    /// Target spec name.
    pub to: String,
    /// Relation kind.
    pub kind: SpecRelationKind,
}

/// Kind of spec relation.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SpecRelationKind {
    /// Dependency relation.
    DependsOn,
    /// Related types.
    RelatedTo,
}

/// SpecFlow statistics.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpecStats {
    /// Number of groups.
    pub groups: usize,
    /// Number of specs.
    pub specs: usize,
    /// Total node count.
    pub nodes: usize,
    /// Total edge count.
    pub edges: usize,
}

/// Lint issue found in specs.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpecLintIssue {
    /// Issue severity.
    pub severity: LintSeverity,
    /// Issue message.
    pub message: String,
    /// Optional location.
    pub location: Option<String>,
}

/// Lint issue severity.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum LintSeverity {
    /// Warning level.
    Warning,
    /// Error level.
    Error,
}

/// Lint result.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpecLintResult {
    /// All issues found.
    pub issues: Vec<SpecLintIssue>,
    /// Number of warnings.
    pub warnings: usize,
    /// Number of errors.
    pub errors: usize,
}

impl SpecLintResult {
    /// Check if there are any errors.
    pub fn has_errors(&self) -> bool {
        self.errors > 0
    }

    /// Check if there are any issues.
    pub fn has_issues(&self) -> bool {
        !self.issues.is_empty()
    }
}