#![cfg_attr(coverage_nightly, coverage(off))]
//! Stub module for backward compatibility during AST migration
//!
//! This module provides minimal stubs to prevent compilation errors.
//! All functionality has been moved to server/src/ast/

use anyhow::Result;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};

// Stub types for backward compatibility
/// Unified ast engine.
pub struct UnifiedAstEngine;

impl Default for UnifiedAstEngine {
    fn default() -> Self {
        Self::new()
    }
}

impl UnifiedAstEngine {
    #[must_use]
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    /// Create a new instance.
    pub fn new() -> Self {
        Self
    }

    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
    pub async fn analyze_project(&self, _path: &Path) -> Result<AstForest> {
        Ok(AstForest::default())
    }

    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
    pub async fn parse_project(&self, _path: &Path) -> Result<AstForest> {
        Ok(AstForest::default())
    }

    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "score_range")]
    /// Compute metrics.
    pub fn compute_metrics(&self, _forest: &AstForest) -> Result<ProjectMetrics> {
        Ok(ProjectMetrics::default())
    }

    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
    /// Extract dependencies.
    pub fn extract_dependencies(
        &self,
        _forest: &AstForest,
    ) -> Result<crate::models::dag::DependencyGraph> {
        Ok(crate::models::dag::DependencyGraph::new())
    }

    /// Generate artifacts for the project
    /// This is a stub implementation for backward compatibility
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
    pub async fn generate_artifacts(&self, _path: &Path) -> Result<ArtifactTree> {
        Ok(ArtifactTree::default())
    }
}

#[derive(Default, Debug, Clone)]
/// Ast forest.
pub struct AstForest {
    pub modules: Vec<ModuleNode>,
    pub metrics: ProjectMetrics,
}

impl AstForest {
    #[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
    /// Files.
    pub fn files(&self) -> impl Iterator<Item = (&PathBuf, &ModuleNode)> {
        self.modules.iter().map(|module| (&module.path, module))
    }
}

#[derive(Default, Debug, Clone)]
/// Module node.
pub struct ModuleNode {
    pub path: std::path::PathBuf,
    pub name: String,
    pub visibility: String,
    pub metrics: ModuleMetrics,
}

#[derive(Default, Debug, Clone)]
/// Module metrics.
pub struct ModuleMetrics {
    pub complexity: u32,
    pub lines: usize,
    pub functions: usize,
    pub classes: usize,
}

#[derive(Default, Debug, Clone)]
/// Project metrics.
pub struct ProjectMetrics {
    pub total_complexity: u32,
    pub total_lines: usize,
    pub file_count: usize,
    pub function_count: usize,
    pub avg_complexity: f32,
    pub max_complexity: u32,
}

// Additional stub types for deterministic_mermaid_engine
#[derive(Default, Debug, Clone)]
/// Artifact tree.
pub struct ArtifactTree {
    pub dogfooding: BTreeMap<String, String>,
    pub mermaid: MermaidArtifacts,
    pub templates: Vec<Template>,
}

#[derive(Default, Debug, Clone)]
/// Mermaid artifacts.
pub struct MermaidArtifacts {
    pub ast_generated: BTreeMap<String, String>,
    pub non_code: BTreeMap<String, String>,
}

#[derive(Debug, Clone)]
/// Template for template generation.
pub struct Template {
    pub name: String,
    pub content: String,
    pub hash: blake3::Hash,
    pub source_location: PathBuf,
}

impl Default for Template {
    fn default() -> Self {
        Self {
            name: String::new(),
            content: String::new(),
            hash: blake3::hash(b""),
            source_location: PathBuf::new(),
        }
    }
}

// FileAst stub enum for backward compatibility
/// AST representation for file.
pub enum FileAst {
    Rust(syn::File),
    TypeScript(String),
    Python(String),
    C(String),
    Cpp(String),
    Cython(String),
    Kotlin(String),
    Makefile(String),
    Markdown(String),
    Toml(String),
    Yaml(String),
    Json(String),
    Shell(String),
}

// --- Include submodules ---
include!("unified_ast_engine_tests.rs");
