package DX::Value::Dict;

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

with 'DX::Role::StructuredValue';

has '+action_builder' => (
  handles => [ qw(
    can_set_value action_for_set_value
    action_for_add_member action_for_remove_member
  ) ]
);

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

sub get_member_at {
  my ($self, $at) = @_;
  $self->members->{ref($at) ? $at->string_value : $at};
}

sub with_member_at {
  my ($self, $at, $value) = @_;
  $self->but(
    members => {
      %{$self->members},
      (ref($at) ? $at->string_value : $at) => $value
    }
  );
}

sub without_member_at {
  my ($self, $at) = @_;
  my %members = %{$self->members};
  delete $members{$at};
  $self->but(members => \%members);
}

1;
