#!/usr/bin/perl

## make sure we can run this from bims via sudo
use lib qw(/home/ernad/ernad/perl /home/ernad/usr/share/perl /home/ernad/lib/perl);

use strict;
use warnings;

use Carp qw(confess);
#use Data::Dumper;
use Getopt::Std;

use Ernad::Presort::Learn;

## options
my %o;
getopts("lmc", \%o) or die;

## check if there are any more outstanding issue
my $do_lazy=$o{'l'};

##
my $do_class_only=$o{'c'};
my $do_model_only=$o{'m'};

my $impna=shift // confess "I need an impna as the first argument.";
my $repcode=shift // confess "I need a repcode as the second argument.";

our $e=Ernad::Erimp->new({'impna'=> $impna, 'verbose'=>3});
$e->{'r'}->load($repcode);

if($do_lazy) {
  use Ernad::IssueState;
  my $issue_doc=&Ernad::IssueState::state_summary_doc($repcode,$e,0);
  my $ernad_ns=$e->{'const'}->{'ernad_ns'};
  my @issues=$issue_doc->getElementsByTagNameNS($ernad_ns,'issue');
  if(scalar @issues) {
    print "I am lazy. I see that you have an issue to do. I exit.\n";
    exit;
  }
}

if(not $o{'c'}) {
  &Ernad::Presort::Learn::model($repcode,$e);
}
if(not $o{'m'}) {
  &Ernad::Presort::Learn::class($repcode,$e);
}
