package DX::Role::Predicate;

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

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

sub _make_equal {
  my ($self, $left, $right) = @_;
  if ($left->equals($right)) {
    return step(
      actions => [],
      depends_on => [
        [ undef ,=> [ CONTENTS_OF ,=> $left ], [ CONTENTS_OF ,=> $right ] ]
      ],
    );
  }
  return (
    do {
      if ($left->is_set and my $set = $right->action_for_set_value($left)) {
        step(
          actions => [ $set ],
          depends_on => [
            [ $right =>
              [ CONTENTS_OF ,=> $left ], [ CONTENTS_OF ,=> $right ]
            ]
          ]
        )
      } else {
        ()
      }
    },
    do {
      if ($right->is_set and my $set = $left->action_for_set_value($right)) {
        step(
          actions => [ $set ],
          depends_on => [
            [ $left =>
              [ CONTENTS_OF ,=> $left ], [ CONTENTS_OF ,=> $right ]
            ]
          ]
        )
      } else {
        ()
      }
    },
  );
}

sub selection_depends_on {
  my ($self, @args) = @_;
  \@args;
}

1;
