package DX::Predicate::Eq;

use DX::Utils qw(rspace res CONTENTS_OF expand_deps);
use DX::Class;

with 'DX::Role::Predicate';

sub _resolution_space_for {
  my ($self, $left, $right) = @_;

  my $deps = expand_deps([
    [ CONTENTS_OF ,=> $left ], [ CONTENTS_OF ,=> $right ]
  ]);

  my $aperture = [ map @{$_->aperture_for_set_value}, $left, $right ];

  if ($left->equals($right)) {
    return rspace(
      geometry_depends_on => $deps,
      aperture => $aperture,
      members => [
        res(
          actions => [],
          veracity_depends_on => $deps,
        )
      ]
    );
  }

  my @members = map {
    my ($set_this, $to_this) = @$_;
    res(
      actions => [ $set_this->action_for_set_value($to_this) ],
      veracity_depends_on => $deps,
    );
  } grep {
    $_->[0]->can_set_value
  } (
    [ $left, $right ],
    [ $right, $left ],
  );

  return rspace(
    geometry_depends_on => $deps,
    aperture => $aperture,
    members => \@members,
  );
}

1;
