package DBIx::Data::Store::Command::Insert::LastInsertId;

use Moose;
use Method::Signatures::Simple;

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

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

has '_last_insert_id_command' => (is => 'ro', lazy_build => 1);

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

method _build__last_insert_id_command {
  $self->raw_store->new_closure_command(sub {
    +{ $self->id_column => shift->last_insert_id((undef) x 4) }
  });
}

method execute {
  $self->insert_call_command->execute;
  return $self->_last_insert_id_command->execute;
};

__PACKAGE__->meta->make_immutable;

1;
