package MpmasCropDbgActivityID;

use strict;
use warnings;
use Exporter;
use Storable qw(dclone);
use Data::Dumper;
use List::Util qw[min max];
use CtUtilities qw(queryhash extqueryhash);
use MpmasInputfile;
use MpmasInputBlock;
our @ISA = qw(MpmasInputfile);

sub filename {
	return "Debug_CropActivityId";
}
sub full_filename {
    my ($self, $mode) = @_;
    if ($self->config_entry("MULTIPERIOD")) {
		return $self->SUPER::full_filename($mode);
	}
    my $dir = $self->outdir();
	my $ext = $self->extension();
	
	if ($mode == 1) {
		$dir = $self->outdir_cm();
		$ext = $self->extension_cm();
	}
    return $dir."Debug"."_".$self->filename() .$ext;
}
sub required {
	my $self = shift;
	return ($self->config_entry("CROP_MODEL") == 3 and $self->config_entry("BIOVERSION") == 4 and  $self->config_entry("XNDEBUGFILES") );
}
sub prepare_shared{

}
sub prepare_special {
		my $self = shift;

		my $sortedxnactivities = $self->get_global("Sorted_Xn_Activities");
		#my $sortedxnactivitiespersoil = $self->get_global("Sorted_Xn_Activities_Per_Soil");

		my $xntop = MpmasInputBlock->new(2,10);
		$xntop->add_comment_row("Debugging Activity IDs");
		$xntop->add_comment_row("This links the external crop growth model to the LP tableau");
		$xntop->add_empty_rows(3);

		$xntop->add_row("1","CROP ACTIVITIES");	
		$xntop->add_row("1.1","INFO ABOUT THE CROP ACTIVITIES");
		$xntop->add_row("", "Number of crop activities (total over all soil types)", scalar @$sortedxnactivities);		
		$xntop->add_row("", "Columns",	1 );	
		$xntop->add_empty_rows(3);
		$self->add_block($xntop);

		my $xnact = MpmasInputBlock->new(3,30);
		$xnact->add_comment_row("","","Cropping activity", " Link ID");
		for my $i (@$sortedxnactivities) {
		  $xnact->add_row( "","",$i->[2], $i->[3]);
		}
		$xnact->add_empty_rows(3);
		$self->add_block($xnact);
		
}
1;
