#!/usr/bin/perl

use strict;
use warnings;
use LATMOS::Accounts;
use Getopt::Long;
use Pod::Usage;

=head1 NAME

    la-sql-log - Dislay objects log

=head1 SYNOPSIS

    la-edit [options] [obj_id]

=cut

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

$otype ||= 'user';

=head1 OPTIONS

=over 4

=item -c|--config configdir

Use this configuration directory instead of the default one.

=item -b|--base basename

Query this specific base instead of the default one.

=item -o|object object_type

Query will be performed on this object. Default is the 'User' object.

=back

=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);

my @logs = $ARGV[0] 
    ? $labase->getobjectlogs($otype, $ARGV[0])
    : $labase->getlogs();

foreach(@logs) {
    printf("%s (%d), %s: %s/%s (%d) %s\n",
        $_->{logdate},
        $_->{irev} || -1,
        $_->{username},
        $_->{otype},
        $_->{name},
        $_->{ikey},
        $_->{message},
    );
}
