package DX::Update::AddValue;

use DX::Utils qw(VALUE_EXISTS);
use DX::Class;

with 'DX::Role::Update';

has new_value => (is => 'ro', required => 1, isa => Value);

sub apply_to {
  my ($self, $scope) = @_;
  my @path = my @whole_path = @{$self->target_path};
  my $target = pop @path;
  my $new_value = $self->new_value;
  return (
    $self->_with_value_at_path(
      $scope, sub { $_[0]->with_member_at($target, $new_value) }, @path
    ),
    [ VALUE_EXISTS ,=> @whole_path ],
  );
}

1;
