//! Integration tests for provisioning generator.

use typedialog_prov_gen::input::CargoIntrospector;
use typedialog_prov_gen::models::{ProjectSpec, ProjectType};

#[test]
fn test_cargo_introspector_sample_project() {
    // Create a simple test manifest
    let manifest_content = r#"
[package]
name = "test-package"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = "0.7"
"#;

    use std::io::Write;
    use tempfile::NamedTempFile;

    let mut temp_file = NamedTempFile::new().expect("Failed to create temp file");
    temp_file
        .write_all(manifest_content.as_bytes())
        .expect("Failed to write to temp file");

    let result = CargoIntrospector::analyze(temp_file.path());
    assert!(result.is_ok(), "Failed to analyze Cargo.toml");

    let spec = result.unwrap();
    assert_eq!(spec.name, "test-package");
    assert_eq!(spec.project_type, ProjectType::WebService);
}

#[test]
fn test_project_spec_validation() {
    use typedialog_prov_gen::models::DomainFeature;

    let spec = ProjectSpec {
        name: "test-project".to_string(),
        project_type: ProjectType::WebService,
        infrastructure: Default::default(),
        domain_features: vec![DomainFeature::new("basic".to_string())],
        constraints: vec![],
        iac_templates: Default::default(),
        scripts: Default::default(),
        docs: Default::default(),
        locales: vec![],
    };

    let result = spec.validate();
    assert!(result.is_ok(), "Valid spec should pass validation");
}

#[test]
fn test_domain_feature_validation() {
    use typedialog_prov_gen::models::DomainFeature;

    let feature = DomainFeature::new(String::new());
    let result = feature.validate();
    assert!(
        result.is_err(),
        "Feature with empty name should fail validation"
    );

    let feature = DomainFeature::new("valid_feature".to_string());
    let result = feature.validate();
    assert!(result.is_ok(), "Valid feature should pass validation");
}

#[test]
fn test_config_field_creation() {
    use typedialog_prov_gen::models::{ConfigField, FieldType};

    let field = ConfigField::new(
        "test_field".to_string(),
        FieldType::Text,
        "Test field prompt".to_string(),
    );

    assert_eq!(field.name, "test_field");
    assert_eq!(field.field_type, FieldType::Text);
    assert!(field.required);
}
