Feature: Estimation Actor
  As a developer
  I want an estimation actor that provides cost, time, and resource estimates
  So that I can make informed decisions before executing plans

  # EstimationResult domain model

  Scenario: EstimationResult can be created with all fields populated
    Given I create an estimation result with all fields
    Then the estimation result should have all expected values

  Scenario: EstimationResult can be created with defaults only
    Given I create an estimation result with defaults
    Then the estimation result summary should be empty
    And the estimation result risk_factors should be empty
    And all optional estimation fields should be None

  Scenario: EstimationResult as_display_dict includes all populated fields
    Given I create an estimation result with all fields
    When I call as_display_dict on the estimation result
    Then the display dict should include estimated_child_plans
    And the display dict should include estimated_time_seconds
    And the display dict should include risk_factors

  Scenario: EstimationResult rejects more than 100 risk_factors
    When I try to create an estimation result with 101 risk factors
    Then a validation error should be raised for risk_factors limit

  Scenario: EstimationResult is frozen (immutable)
    Given I create an estimation result with defaults
    When I try to modify the estimation result summary
    Then a validation error should be raised for frozen model

  Scenario: EstimationResult can be serialized to dict and back
    Given I create an estimation result with all fields
    When I serialize the estimation result to dict
    And I deserialize it back to an EstimationResult
    Then the deserialized result should match the original

  # Plan model accepts estimation_result

  Scenario: Plan model accepts estimation_result field
    Given I have a plan lifecycle service for estimation tests
    And I have an available action for estimation tests
    When I use the action to create a plan for estimation tests
    And I set an estimation result on the plan
    Then the plan estimation_result should be set

  Scenario: Plan as_cli_dict includes estimation when present
    Given I have a plan lifecycle service for estimation tests
    And I have an available action for estimation tests
    When I use the action to create a plan for estimation tests
    And I set an estimation result on the plan
    Then the plan cli dict should include estimation data

  # Plans work without estimation actor (optional behavior)

  Scenario: Plans work without estimation actor configured
    Given I have a plan lifecycle service for estimation tests
    When I create an action without estimation actor for estimation tests
    And I use that action to create an estimation test plan
    Then the plan estimation_actor should be None
    And the plan estimation_result should be None

  # EstimationStubActor

  Scenario: EstimationStubActor produces placeholder result
    When I run the estimation stub actor with a valid plan id
    Then the stub result summary should contain "stub actor"

  Scenario: EstimationStubActor rejects empty plan_id
    When I run the estimation stub actor with an empty plan id
    Then a validation error should be raised for estimation

  # ActorRole enum includes ESTIMATOR

  Scenario: ActorRole enum includes ESTIMATOR
    Then the ActorRole enum should have an ESTIMATOR value
    And the ESTIMATOR value should be "estimator"

  # Estimation invocation in plan lifecycle

  Scenario: Estimation runs when estimation_actor is set during Strategize to Execute transition
    Given I have a plan lifecycle service for estimation tests
    And I have an action with estimation actor set
    When I use the estimation action and complete strategize
    And I transition the estimation plan to execute phase
    Then the plan estimation_result should be set

  Scenario: Estimation is skipped when estimation_actor is not set
    Given I have a plan lifecycle service for estimation tests
    And I have an action without estimation actor
    When I use the estimation action and complete strategize
    And I transition the estimation plan to execute phase without estimation
    Then the plan estimation_result should be None
