package DX::ActionBuilder::Null;

use DX::Class;

with 'DX::Role::ActionBuilder';

has target_path => (is => 'ro', isa => ValuePath);

sub can_set_value { 0 }

sub aperture_for_set_value { [] }

sub action_for_set_value { undef }

sub can_add_member { 0 }

sub aperture_for_add_member { [] }

sub action_for_add_member { undef }

sub aperure_for_set_member { [] }

sub action_for_set_member { undef }

sub aperture_for_remove_member { [] }

sub action_for_remove_member { undef }

sub specialize_for_member {
  my ($self, $at) = @_;
  return $self unless ref($self);
  return $self unless my $path = $self->target_path;
  return $self->but(
    target_path => [ @{$self->target_path}, $at ]
  );
}

sub apply_to_value {
  my ($self, $value) = @_;
  my $new_value = $value->but_set_action_builder($self);
  return $new_value unless $new_value->isa('DX::Value::Dict');
  my %m = %{$new_value->members};
  return $new_value->but(
    members => {
      map +($_ => $self->specialize_for_member($_)->apply_to_value($m{$_})),
        keys %m,
    },
  );
}

1;
