package MpmasConstraintInfo;

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

sub filename {
	return "ConstraintInfo";
}

sub extension {
	return ".txt";
}
sub leftmargin {
	return "";
}
sub prepare_special {
	my $self = shift;
	
	my $NumRow = $self->milpinfo("NumRow");
	my $NumCol = $self->milpinfo("NumCol");
	my $numMilps = scalar @{ $self->milplist };
	my $cinfo;
	if ($NumCol > $self->config_entry("LIMIT_FOR_IMMEDIATE") / $numMilps or $NumRow > $self->config_entry("LIMIT_FOR_IMMEDIATE") / $numMilps) {
		$cinfo = MpmasInputBlockImmediate->new(0,10,1);
	}
	else {
		$cinfo = MpmasInputBlock->new(0,10);
	}
	
	my @SortedConstraintGroupings = sort{$a cmp $b} keys %{$self->config_entry("Groupings")->{constraint}};
	$cinfo->add_row("Row","Code","Name","OutfileCol","MpmasqlType", $self->config_entry("MULTIPERIOD") ? "Unit" : ()  , $self->config_entry("MULTIPERIOD") ? "MPeriod" : (), @SortedConstraintGroupings);
	for my $i (@{$self->sorted_constraint_objects}) {
		my $row = $i->lp_row + 15;
		my @temp = ( $i->lp_row, $i->id, $i->attr("name"), $row,  $i->attr("type"));	
		if ($self->config_entry("MULTIPERIOD")) {
			push @temp, $i->attr("unit");
			push @temp, $i->attr("mperiod");
		}
		for my $j (@SortedConstraintGroupings) {				
			my $group = -1;
			$group = $i->get_group($j) if (defined $i->get_group($j) );
			push @temp, "$group";
		}
		$cinfo->add_row(@temp);
	}
	$self->add_block($cinfo);

}
1;
