package System::Introspector::Report::Config;
use Moo;
use Config::General;
use Module::Runtime qw( use_module );

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

sub _build_config {
  my ($self) = @_;
  return +{
    Config::General->new($self->config_file)->getall,
  };
}

sub report_types {
  my ($self) = @_;
  my $reports = $self->config->{report} || {};
  return map {
    [$_, $reports->{$_}];
  } sort keys %$reports;
}

sub publishers {
  my ($self, @override) = @_;
  my $publish = $self->config->{publish} || {};
  return map {
    use_module("System::Introspector::Report::Publish::$_")
      ->new($publish->{$_} || {});
  } @override ? @override : sort keys %$publish;
}

1;
