package DX::ActionPolicy::LockScope;

use DX::Class;

with 'DX::Role::ActionPolicy';

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

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

sub allows {
  my ($self, $action) = @_;
  my $first = $action->target_path->[0];
  return 0 unless $first =~ /^(\d+)$/ and $first > $self->lock_to_depth;
  return $self->next_policy->allows($action);
}

1;
