use crate::GeneratedFile;

/// In-memory representation of a crate's module tree.
///
/// Built from rustdoc JSON, representing the hierarchical structure of modules and items.
#[derive(Debug)]
pub struct ModuleGraph {
    /// Crate name.
    pub crate_name: String,

    /// Root module containing the entire tree.
    pub root: ModuleNode,
}

/// Tree node representing a single module.
///
/// Contains module metadata plus recursive structure of child modules and items.
#[derive(Debug, Clone)]
pub struct ModuleNode {
    /// Simple module name (e.g., `"utils"`).
    pub name: String,

    /// Fully-qualified path (e.g., `"my_crate::utils"`).
    pub fqpath: String,

    /// Module documentation text.
    pub docs: String,

    /// Child modules (recursive tree structure).
    pub children: Vec<ModuleNode>,

    /// Items defined in this module.
    pub items: Vec<ModItem>,
}

/// Categories of items that can appear in a module.
///
/// Used to classify and group items for rendering.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
pub enum ModItemKind {
    /// Free functions (methods inside `impl`s are not included).
    Function,
    /// Struct types.
    Struct,
    /// Enum types.
    Enum,
    /// Trait definitions.
    Trait,
    /// Constant values.
    Constant,
    /// Type alias declarations.
    TypeAlias,
    /// Re-exported items.
    ReExport,
}

/// Metadata for a single item in a module.
///
/// Captures all information needed to render an item's documentation.
#[derive(Debug, Clone)]
pub struct ModItem {
    /// Item category (function, struct, etc.).
    pub kind: ModItemKind,

    /// Simple item name (e.g., `"Config"`).
    pub name: String,

    /// Fully-qualified path (e.g., `"my_crate::Config"`).
    pub qualified: String,

    /// Documentation text.
    pub docs: String,

    /// Rendered signature when available (functions, struct-like items, type aliases,
    /// constants, and re-exports currently populate this field).
    pub signature: Option<String>,
}

/// Output from a single crate renderer pass.
///
/// Internal type used by individual renderers (`ModuleTreeRenderer`, `ModuleSingleRenderer`).
/// Multiple `RenderOutput` instances are aggregated into a `GeneratedDocs` by `render_targets()`.
///
/// For the public API, use `GeneratedDocs` instead.
#[derive(Debug)]
pub(crate) struct RenderOutput {
    pub files: Vec<GeneratedFile>,
    pub summary_fragment: String,
}
