package Tak::ServiceManager;

use Moo;

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

sub start_request {
  my ($self, $req, $type, @args) = @_;
  unless ($type) {
    $req->respond(MISTAKE => request_type => "No request type given");
    return;
  }
  my $service = $self->service;
  if (my $meth = $service->can("handle_${type}")) {
    $req->respond($service->$meth(@args));
    return;
  }
  $req->respond(MISTAKE => request_type => "Unknown request type ${type}");
}

1;
