package DX::Role::Predicate;

use List::Util qw(reduce);
use DX::Utils qw(step CONTENTS_OF);
use DX::Role;

sub _possible_resolution_list {
  my ($self, @args) = @_;
  my $rspace = $self->_resolution_space_for(@args);
  my @res;
  while (my $next_res = $rspace->next_resolution) {
    $rspace = $rspace->remaining_resolution_space;
    push @res, step(
      actions => $next_res->actions,
      depends_on => $next_res->veracity_depends_on,
    );
  }
  return @res;
}

sub resolution_step_for {
  my ($self, $prop, @args) = @_;
  my ($last, @rest) = reverse $self->_possible_resolution_list(@args);
  return undef unless $last;
  my $targ = $last->but(resolves => $prop);
  $targ = $_->but(
    alternative_step => $targ,
    resolves => $prop
  ) for @rest;
  return $targ;
}

1;
