package DX::Step::CompleteRecheck;

use DX::Class;

with 'DX::Role::Step';

has was_recheck_for => (is => 'ro', isa => Proposition, required => 1);

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

sub apply_to {
  my ($self, $ss) = @_;

  trace recheck => [ statement => [ [ symbol => 'complete_recheck' ] ] ];
  trace recheck => [ 'leave_block' ];

  my $prop = $self->was_recheck_for;
  my $re_ss = $self->resume_search_state;
  my $re_hyp = $re_ss->current_hypothesis;
  my $re_rps = $re_hyp->resolved_propositions;

  my $rps = $re_rps->with_updated_dependencies_for(
    $prop,
    $ss->current_hypothesis
       ->resolved_propositions
       ->dependencies_for($prop)
  );

  return $re_ss->but(
    current_hypothesis => $re_hyp->but(
      resolved_propositions => $rps
    ),
  );
}

1;
