package MpmasEDICIrrigation;

use strict;
use warnings;
use Exporter;
use Storable qw(dclone);
use Data::Dumper;
use MpmasInputfile;
use MpmasInputBlock;
use IndexedTable;
our @ISA = qw(MpmasInputfile);

sub filename {
	return "EdicIrrigationMethods0";
}
sub required {
      my $self = shift;
      return 1 if ($self->config_entry("LANDSCAPE_MODEL") == 1);
}
sub prepare_shared {
	my $self = shift;
	my $dbh = $self->get_dbh;
	my $t  = $self->config_entry("EDICIRRIGMETHODS")->transform($dbh,1);
	my @methodlist = sort {$a <=> $b} $t->query([],0);
	my $count = 0;
	for my $i ( @methodlist) {
	      $t->set_column_value([$i],9,$count);
	      $count++;
	}
	
	$self->set_config_entry("EDICIRRIGMETHODS_TAB", $t);
	$self->set_config_entry("NUMIRRIGMETH", scalar @methodlist);
}


sub prepare_special {
	my $self = shift;	

	my $block2 = MpmasInputBlock->new(3,20);
	$block2->add_comment_row("ID","Irrigation method","MPMAS_ID","Name","Surface runoffs at night","Evapotranspiration","surface","subsurface","groundwater");
	my $t = $self->config_entry("EDICIRRIGMETHODS_TAB");
	for my $i (sort {$t->query([$a],9) <=> $t->query([$b],9)} $t->query([],0) ) {
	      $block2->add_row($i, $t->query([$i],2),$t->query([$i],9), $t->query([$i],3),$t->query([$i],4),$t->query([$i],5),$t->query([$i],6),$t->query([$i],7),$t->query([$i],8));
	}
	my $block1 = MpmasInputBlock->new(3,10);	
	$block1->add_row("THE IRRIGATION METHODS FILE");
	$block1->add_empty_rows(3);
	$block1->add_row("IRRIGATION METHODS");
	$block1->add_row("1.1",	"Number of irrigation methods","",$self->config_entry("NUMIRRIGMETH"));
	$block1->add_row("1.2","Table with parameter values");
	

			
	$self->add_block($block1);
	$self->add_block($block2);
}