package DX::ActionBuilder::UnsetValue;

use DX::Action::SetValue;
use DX::ActionBuilder::Normal;
use DX::Action::BindValue;
use DX::ActionBuilder::BoundValue;
use DX::Utils qw(VALUE_SET);
use DX::Class;

with 'DX::Role::ActionBuilder';

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

sub aperture_for_set_value {
  [ [ VALUE_SET ,=> @{$_[0]->target_path} ] ]
}

sub action_for_set_value {
  my ($self, $value) = @_;
  if (my $p = $value->value_path) {
    my $ab = DX::ActionBuilder::BoundValue->new(
      target_path => $self->target_path,
      rebind_path => $self->target_path,
      bound_to_path => $p,
      inner_action_builder => $value->action_builder,
    );
    return DX::Action::BindValue->new(
      target_path => $self->target_path,
      new_value => $ab->apply_to_value($value, $value),
    )
  }
  DX::ActionBuilder::Normal->new(
    target_path => $self->target_path,
  )->action_for_set_value($value);
}

1;
