use std::collections::BTreeMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::dependency_tree::ArtifactKind;
use crate::front_matter::ArtifactFrontMatter;
pub const WORKSPACE_INDEX_SCHEMA_VERSION: u32 = 2;
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ArtifactKey {
pub kind: ArtifactKind,
pub workspace_path: String,
}
#[derive(Clone, Debug)]
pub struct ArtifactRecord {
pub key: ArtifactKey,
pub absolute_path: PathBuf,
pub front_matter: Option<ArtifactFrontMatter>,
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct HeadingIdentifier {
pub artifact: ArtifactKey,
pub slug: String,
}
#[derive(Clone, Debug)]
pub struct HeadingRecord {
pub id: HeadingIdentifier,
pub level: u8,
pub title: String,
pub order: usize,
pub parent: Option<HeadingIdentifier>,
pub children: Vec<HeadingIdentifier>,
pub content: String,
pub referenced_headings: Vec<HeadingIdentifier>,
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ConstraintIdentifier {
pub artifact: ArtifactKey,
pub group: String,
}
#[derive(Clone, Debug)]
pub struct ConstraintRecord {
pub id: ConstraintIdentifier,
pub heading: HeadingIdentifier,
pub line: usize,
pub referenced_headings: Vec<HeadingIdentifier>,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum RelationshipKind {
HeadingToArtifact,
HeadingToHeading,
HeadingToFile,
ConstraintToHeading,
ParentToChild,
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RelationshipEdge {
pub kind: RelationshipKind,
pub from: String,
pub to: String,
}
#[derive(Clone, Debug, Default)]
pub struct WorkspaceIndex {
pub schema_version: u32,
pub workspace_root: PathBuf,
pub artifacts: BTreeMap<ArtifactKey, ArtifactRecord>,
pub headings: BTreeMap<HeadingIdentifier, HeadingRecord>,
pub constraints: BTreeMap<ConstraintIdentifier, ConstraintRecord>,
pub relationships: Vec<RelationshipEdge>,
}