#!/usr/bin/perl

use strict;
use warnings;
use LATMOS::Accounts;
use LATMOS::Accounts::Bases::Sql::DataRequest;
use LATMOS::Accounts::Log;
use Getopt::Long;
use Pod::Usage;

=head1 NAME

    la-sql-list-request - List pending change request

=head1 SYNOPSIS

    la-sql-list-request

=cut

GetOptions(
    'c|config=s' => \my $config,
    'b|base=s'   => \my $base,
    'help'       => sub { pod2usage(0) },
) or pod2usage();

=head1 OPTIONS

=over 4

=item -c|--config configdir

Use this configuration directory instead of the default one.

=item -b|--base base

Use this base instead default one

=back

=head1 CONFIGURATION

Some variables are taken from configuration directory:

=over 4

=cut

my $LA = LATMOS::Accounts->new($config, noacl => 1);
my $labase = $LA->base($base);
$labase && $labase->load or die "Cannot load base";
$labase->wexported(1);

foreach ($labase->list_requests) {
    my $datareq = $labase->get_datarequest($_);

    printf("%-05d %-10s: by %-10s %-11s %s\n",
        $datareq->ar_id,
        $datareq->accreq->id,
        $datareq->user || '(nobody)',
        $datareq->oobject ? $datareq->oobject->id : '',
        $datareq->apply,
    )
}

exit(0);
