package LolCatalyst::Lite::SnippetStore;

use Moose;
use aliased 'LolCatalyst::Lite::Snippet';
use namespace::clean -except => 'meta';

has '_snippets' => (is => 'ro', default => sub { [] });
has '_translator' => (
  is => 'ro',
  required => 1,
  lazy => 1,
  default => sub {
    confess "_translator object requested but never supplied"
  },
  init_arg => 'translator'
);

sub find {
  my ($self, $id) = @_;
  $self->_snippets->[$id - 1];
}

sub all {
  my ($self) = @_;
  @{$self->_snippets};
}

sub create {
  my ($self, $new) = @_;
  my $snippet = Snippet->new(
    %$new,
    id => (@{$self->_snippets} + 1),
    translator => $self->_translator
  );
  push(@{$self->_snippets}, $snippet);
  $snippet;
}

__PACKAGE__->meta->make_immutable;

1;
