//! Path conventions for project storage.

use std::path::{Path, PathBuf};
use uuid::Uuid;

/// Path helper for the projects storage root.
pub struct ProjectPaths {
    root: PathBuf,
}

impl ProjectPaths {
    /// Create a new path helper.
    pub fn new(root: impl Into<PathBuf>) -> Self {
        Self { root: root.into() }
    }

    /// Root directory for all projects.
    pub fn root(&self) -> &Path {
        &self.root
    }

    /// Directory for a specific project.
    pub fn project_dir(&self, project_id: &Uuid) -> PathBuf {
        self.root.join(project_id.to_string())
    }

    /// Path to the project metadata JSON file.
    pub fn project_json(&self, project_id: &Uuid) -> PathBuf {
        self.project_dir(project_id).join("project.json")
    }

    /// Path to the repositories JSON file (Phase 2).
    pub fn repositories_json(&self, project_id: &Uuid) -> PathBuf {
        self.project_dir(project_id).join("repositories.json")
    }

    /// Path to the bindings JSON file (Phase 5).
    pub fn bindings_json(&self, project_id: &Uuid) -> PathBuf {
        self.project_dir(project_id).join("bindings.json")
    }

    /// Path to the worktrees JSON file (Phase 4).
    pub fn worktrees_json(&self, project_id: &Uuid) -> PathBuf {
        self.project_dir(project_id).join("worktrees.json")
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_project_paths() {
        let paths = ProjectPaths::new("/data/projects");
        let id = Uuid::nil();

        assert_eq!(
            paths.project_dir(&id),
            PathBuf::from("/data/projects/00000000-0000-0000-0000-000000000000")
        );
        assert_eq!(
            paths.project_json(&id),
            PathBuf::from("/data/projects/00000000-0000-0000-0000-000000000000/project.json")
        );
    }
}
