package DX::Step::CompleteResolution;

use DX::Class;

with 'DX::Role::Step';

has original_search_state => (
  is => 'ro', isa => SearchState, required => 1
);

has resolution_space => (
  is => 'ro', isa => ResolutionSpace, required => 1
);

sub apply_to {
  my ($self, $old_ss) = @_;
  my $orig_ss = $self->original_search_state;
  my $ns = do {
    if (my $prop = $orig_ss->next_proposition) {
      $prop->consider_step
    } else {
      $old_ss->on_solution_step
    }
  };
  return $old_ss->but(
    next_step => $ns,
    decisions_taken => [
      [ $self->resolution_space, $orig_ss ],
      @{$old_ss->decisions_taken}
    ],
  );
}

1;
