Feature: PLAN_APPLIED event enrichment with changeset statistics
  As an audit log consumer
  I want the PLAN_APPLIED domain event to include changeset statistics
  So that audit entries contain rich context per SEC7 requirements

  Background:
    Given a plan applied event enrichment test environment

  # -- complete_apply passes statistics to event -------------------------

  Scenario: complete_apply emits PLAN_APPLIED with files_changed statistic
    Given a plan in Apply/PROCESSING state
    When complete_apply is called with files_changed=5
    Then the emitted PLAN_APPLIED event details should include files_changed=5

  Scenario: complete_apply emits PLAN_APPLIED with lines_added statistic
    Given a plan in Apply/PROCESSING state
    When complete_apply is called with lines_added=42
    Then the emitted PLAN_APPLIED event details should include lines_added=42

  Scenario: complete_apply emits PLAN_APPLIED with lines_removed statistic
    Given a plan in Apply/PROCESSING state
    When complete_apply is called with lines_removed=7
    Then the emitted PLAN_APPLIED event details should include lines_removed=7

  Scenario: complete_apply emits PLAN_APPLIED with resources_modified statistic
    Given a plan in Apply/PROCESSING state
    When complete_apply is called with resources_modified=3
    Then the emitted PLAN_APPLIED event details should include resources_modified=3

  Scenario: complete_apply emits PLAN_APPLIED with apply_duration_seconds statistic
    Given a plan in Apply/PROCESSING state
    When complete_apply is called with apply_duration_seconds=1.5
    Then the emitted PLAN_APPLIED event details should include apply_duration_seconds=1.5

  Scenario: complete_apply emits PLAN_APPLIED with all statistics combined
    Given a plan in Apply/PROCESSING state
    When complete_apply is called with all changeset statistics
    Then the emitted PLAN_APPLIED event details should include all changeset statistics

  Scenario: complete_apply emits PLAN_APPLIED with zero statistics by default
    Given a plan in Apply/PROCESSING state
    When complete_apply is called with no changeset statistics
    Then the emitted PLAN_APPLIED event details should include files_changed=0
    And the emitted PLAN_APPLIED event details should include lines_added=0
    And the emitted PLAN_APPLIED event details should include lines_removed=0
    And the emitted PLAN_APPLIED event details should include resources_modified=0
    And the emitted PLAN_APPLIED event details should include apply_duration_seconds=0.0

  Scenario: complete_apply preserves existing event details alongside statistics
    Given a plan applied event enrichment test environment
    Given a plan in Apply/PROCESSING state with action_name "deploy-service"
    When complete_apply is called with files_changed=2
    Then the emitted PLAN_APPLIED event details should include action_name "deploy-service"
    And the emitted PLAN_APPLIED event details should include files_changed=2

  # -- apply_with_validation_gate passes statistics through ---------------

  Scenario: apply_with_validation_gate passes files_changed to complete_apply
    Given a plan with changeset containing 4 entries
    And the plan has no validation failures
    When apply_with_validation_gate is called
    Then complete_apply should be called with files_changed=4

  Scenario: apply_with_validation_gate passes resources_modified to complete_apply
    Given a plan with changeset containing entries for 2 distinct resources
    And the plan has no validation failures
    When apply_with_validation_gate is called
    Then complete_apply should be called with resources_modified=2

  Scenario: apply_with_validation_gate passes apply_duration_seconds to complete_apply
    Given a plan with changeset containing 1 entries
    And the plan has no validation failures
    When apply_with_validation_gate is called
    Then complete_apply should be called with a non-negative apply_duration_seconds

  Scenario: apply_with_validation_gate passes lines_added from creates to complete_apply
    Given a plan with changeset containing 3 CREATE entries
    And the plan has no validation failures
    When apply_with_validation_gate is called
    Then complete_apply should be called with lines_added=3

  Scenario: apply_with_validation_gate passes lines_removed from deletes to complete_apply
    Given a plan with changeset containing 2 DELETE entries
    And the plan has no validation failures
    When apply_with_validation_gate is called
    Then complete_apply should be called with lines_removed=2
