package DX::ResolutionSpace;

use DX::Step::Backtrack;
use DX::Step::ResolveProposition;
use DX::Class;

has proposition => (is => 'ro');

has geometry_depends_on => (is => 'ro', required => 1);

has aperture => (is => 'ro', required => 1);

has members => (is => 'ro', required => 1);

sub for_deparse {
  my ($self) = @_;
  [ statement => [
    [ symbol => 'rspace' ],
    [ block => $self->members ],
  ] ];
}

sub next_resolution {
  my ($self) = @_;
  return undef unless my ($first) = @{$self->members};
  return $first->next_resolution;
}

sub remaining_resolution_space {
  my ($self) = @_;
  die "Sense makes not" unless my ($first, @rest) = @{$self->members};
  return $self->but(members => [ $first->remainder, @rest ]);
}

sub next_step {
  my ($self) = @_;
  return DX::Step::Backtrack->new unless @{$self->members};
  return DX::Step::ResolveProposition->new(resolution_space => $self);
}

1;
