package System::Introspector::Report::Builder::HostInfo;
use Moo;

extends 'System::Introspector::Report::Builder';

has _hostinfo => (is => 'ro', default => sub { {} });

sub required_data {
  return qw( host );
}

sub collect_from {
  my ($self, $id, $data) = @_;
  $self->_hostinfo->{$id}{hostname} = $data->{host}{hostname};
  return 1;
}

sub render_reports {
  my ($self) = @_;
  my @columns = (
    { key => 'info-field', label => 'Info' },
    { key => 'info-value', label => 'Value' },
  );
  return map {
    my $remote = $_;
    +{
      columns   => [@columns],
      title     => "Host Information for $remote",
      id        => ['host-info-by-remote', $remote],
      rowid     => [qw( info-field )],
      meta      => { remote => $remote },
      rows      => [
        +{
          'info-field' => 'Hostname',
          'info-value' => $self->_hostinfo->{$remote}{hostname},
        },
      ],
    };
  } keys %{$self->_hostinfo};
}

1;
