// Sprint 84 TDD: run_enforcement_step complexity reduction (21 → ≤10)
// Following RED-GREEN-REFACTOR methodology with A+ standards
// NOTE: This test is temporarily disabled as it tests private internal APIs
// that have been refactored. The functionality is tested through public APIs.

#![cfg(test)]
#![allow(dead_code, unused_imports)]

// NOTE: This entire test file is disabled as it tests private internal APIs
// that have been refactored and are no longer accessible for testing.

use anyhow::Result;
use pmat::cli::handlers::enforce_handlers::*;
use pmat::cli::EnforceOutputFormat;
use std::path::PathBuf;

/// Test data for Sprint 84 TDD refactoring
struct TestData {
    project_path: PathBuf,
    profile: QualityProfile,
    config: EnforcementConfig,
}

impl Default for TestData {
    fn default() -> Self {
        Self {
            project_path: PathBuf::from("./server"),
            profile: QualityProfile::default(),
            config: EnforcementConfig::default(),
        }
    }
}

// ========== RED PHASE TESTS (Should fail initially) ==========

#[tokio::test]
async fn test_handle_analyzing_enforcement_state_extraction() -> Result<()> {
    let data = TestData::default();

    // Test extracted function for analyzing state within enforcement step
    let result = handle_analyzing_enforcement_state(
        &data.project_path,
        &data.profile,
        false, // single_file_mode
        true,  // dry_run
        None,  // specific_file
    )
    .await?;

    assert!(matches!(
        result.state,
        EnforcementState::Analyzing | EnforcementState::Violating | EnforcementState::Complete
    ));
    assert!(result.score >= 0.0 && result.score <= 1.0);
    assert_eq!(result.target, 1.0);

    Ok(())
}

#[tokio::test]
async fn test_handle_violating_enforcement_state_extraction() -> Result<()> {
    let _violations = vec![QualityViolation {
        violation_type: "complexity".to_string(),
        severity: "high".to_string(),
        location: "test.rs:1".to_string(),
        current: 25.0,
        target: 20.0,
        suggestion: "Test violation".to_string(),
    }];

    // Test extracted function for violating state within enforcement step
    let result = handle_validating_enforcement_state(
        &PathBuf::from("./server"),
        &QualityProfile::default(),
        false, // single_file_mode
        true,  // dry_run
        None,  // specific_file
        None,  // include_pattern
        None,  // exclude_pattern
    )
    .await?;

    assert!(matches!(result.state, EnforcementState::Violating));
    assert_eq!(result.next_action, "manual_intervention_required");
    assert_eq!(result.violations.len(), 1);

    Ok(())
}

#[tokio::test]
async fn test_handle_refactoring_enforcement_state_extraction() -> Result<()> {
    // Test extracted function for refactoring state within enforcement step
    let result = handle_refactoring_enforcement_state(
        0.6,  // total_score
        None, // specific_file
    )?;

    assert!(matches!(result.state, EnforcementState::Validating));
    assert!(result.score > 0.6); // Should improve score
    assert_eq!(result.next_action, "validate_changes");
    assert!(result.violations.is_empty());

    Ok(())
}

#[tokio::test]
async fn test_handle_validating_enforcement_state_extraction() -> Result<()> {
    let data = TestData::default();

    // Test extracted function for validating state within enforcement step
    let result = handle_validating_enforcement_state(
        &data.project_path,
        &data.profile,
        false, // single_file_mode
        true,  // dry_run
        None,  // specific_file
        None,  // include_pattern
        None,  // exclude_pattern
    )
    .await?;

    // Should transition based on re-analysis results
    assert!(matches!(
        result.state,
        EnforcementState::Complete | EnforcementState::Violating
    ));

    Ok(())
}

#[tokio::test]
async fn test_handle_complete_enforcement_state_extraction() -> Result<()> {
    // Test extracted function for complete state within enforcement step
    let result = handle_complete_enforcement_state()?;

    assert!(matches!(result.state, EnforcementState::Complete));
    assert_eq!(result.score, 1.0);
    assert_eq!(result.target, 1.0);
    assert_eq!(result.next_action, "none");
    assert!(result.violations.is_empty());
    assert_eq!(result.progress.files_remaining, 0);

    Ok(())
}

/* DISABLED: Private API test that needs refactoring
#[tokio::test]
async fn test_refactored_run_enforcement_step_complexity_reduction() -> Result<()> {
    let data = TestData::default();

    // Integration test - refactored function should behave identically
    // but with ≤10 complexity (A+ standard)
    let result = run_enforcement_step(
        &data.project_path,
        &data.profile,
        EnforcementState::Analyzing,
        data.config.single_file_mode,
        data.config.dry_run,
        data.config.apply_suggestions,
        data.config.specific_file.as_ref(),
        data.config.include_pattern.as_ref(),
        data.config.exclude_pattern.as_ref(),
    )
    .await?;

    // Should complete with valid result
    assert!(matches!(
        result.state,
        EnforcementState::Analyzing | EnforcementState::Violating | EnforcementState::Complete
    ));
    assert!(result.score >= 0.0 && result.score <= 1.0);

    Ok(())
}
*/

#[test]
fn test_enforcement_state_transition_logic() {
    // Test the logic for state transitions within enforcement step

    // Test analyzing → violating transition
    let has_violations = true;
    let next_state = if has_violations {
        EnforcementState::Violating
    } else {
        EnforcementState::Complete
    };
    assert_eq!(next_state, EnforcementState::Violating);

    // Test complete state properties
    let no_violations = false;
    let final_state = if no_violations {
        EnforcementState::Violating
    } else {
        EnforcementState::Complete
    };
    assert_eq!(final_state, EnforcementState::Complete);
}

/* DISABLED: Private API test
#[tokio::test]
async fn test_enforcement_step_with_suggestions() -> Result<()> {
    let data = TestData::default();

    // Test enforcement step with apply_suggestions=true
    let result = run_enforcement_step(
        &data.project_path,
        &data.profile,
        EnforcementState::Violating,
        false, // single_file_mode
        false, // dry_run (not dry run so suggestions can apply)
        true,  // apply_suggestions
        None,  // specific_file
        None,  // include_pattern
        None,  // exclude_pattern
    )
    .await?;

    // Should handle suggestions appropriately
    assert!(result.score >= 0.0 && result.score <= 1.0);

    Ok(())
}
*/

/* DISABLED: Private API test
#[tokio::test]
async fn test_enforcement_step_recursive_validation() -> Result<()> {
    let data = TestData::default();

    // Test validating state which recursively calls enforcement step
    let result = run_enforcement_step(
        &data.project_path,
        &data.profile,
        EnforcementState::Validating,
        data.config.single_file_mode,
        data.config.dry_run,
        false, // Don't apply suggestions during validation
        data.config.specific_file.as_ref(),
        data.config.include_pattern.as_ref(),
        data.config.exclude_pattern.as_ref(),
    )
    .await?;

    // Should override state based on validation results
    assert!(matches!(
        result.state,
        EnforcementState::Complete | EnforcementState::Violating
    ));

    Ok(())
}
*/
