// Tests for mecha10_cli::services::project_template_service

use mecha10_cli::services::project_template_service::*;

use tempfile::TempDir;

#[test]
fn test_project_template_service_creation() {
    let _service = ProjectTemplateService::new();
    // Service creation succeeds if we reach here without panic
}

#[tokio::test]
async fn test_create_readme() -> Result<()> {
    let temp = TempDir::new()?;
    let service = ProjectTemplateService::new();

    service.create_readme(temp.path(), "test-robot").await?;

    let readme_path = temp.path().join("README.md");
    assert!(readme_path.exists());

    let content = tokio::fs::read_to_string(readme_path).await?;
    assert!(content.contains("# test-robot"));
    assert!(content.contains("Mecha10"));

    Ok(())
}

#[tokio::test]
async fn test_create_gitignore() -> Result<()> {
    let temp = TempDir::new()?;
    let service = ProjectTemplateService::new();

    service.create_gitignore(temp.path()).await?;

    let gitignore_path = temp.path().join(".gitignore");
    assert!(gitignore_path.exists());

    let content = tokio::fs::read_to_string(gitignore_path).await?;
    assert!(content.contains("/target/"));
    assert!(content.contains(".env"));

    Ok(())
}

#[tokio::test]
async fn test_create_cargo_toml() -> Result<()> {
    let temp = TempDir::new()?;
    let service = ProjectTemplateService::new();

    service.create_cargo_toml(temp.path(), "test-robot", false).await?;

    let cargo_toml_path = temp.path().join("Cargo.toml");
    assert!(cargo_toml_path.exists());

    let content = tokio::fs::read_to_string(cargo_toml_path).await?;
    assert!(content.contains("name = \"test-robot\""));
    assert!(content.contains("mecha10-core"));

    Ok(())
}
