package DX::Step::Backtrack;

use DX::Class;

with 'DX::Role::Step';

sub apply_to {
  my ($self, $ss) = @_;
  trace backtrack => [ statement => [ [ symbol => 'backtrack' ] ] ];
  foreach my $adj (@{$ss->decisions_taken}) {
    my ($rspace_was, $ss_was) = @$adj;
    trace rspace => [ statement => [
      [ symbol => 'remaining' ],
      @{$rspace_was->remaining_resolution_space->for_deparse->[1]}
    ] ];
    return $ss_was->but(
      next_step => $rspace_was->remaining_resolution_space->next_step
    );
  }
  return $ss->but(next_step => $ss->on_exhaustion_step);
}

1;
