package App::Clifton::Server;

use aliased 'App::Clifton::ServiceContainer';
use aliased 'App::Clifton::ConfigLoader';
use Moo;

extends 'App::Clifton::Service';

sub BUILD {
  my ($self, $args) = @_;
  $args->{loop}->add($self);
  $self->$_ for qw(services);
}

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

has config_loader => (is => 'lazy');

sub _build_config_loader { ConfigLoader->new }

has services => (is => 'lazy');

sub _build_services {
  shift->_new_child(ServiceContainer, {});
}

sub reload_config { shift->_do(reload_config => @_) }
sub shutdown { shift->_do(shutdown => @_) }

sub _body_for_reload_config {
  my ($self, $args) = @_;
  $args->{on_finished}->();
}

1;
