package MpmasCommonProperty;

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

sub filename {
	my $self = shift;
	return "CommonProperty0";
}

sub required {
	my ($self) = @_;
	

	return ($self->config_entry("MULTIPERIOD") && $self->config_entry("COMMON_PROPERTY") > 0 ); 
}
sub prepare_shared {
	my ($self) = @_;

	$self->set_config_entry("POLICY_MODEL", $self->config_entry("POLICY_MODEL") + 32);
	
	
    print STDERR "\nError: Missing COMMON_PROPERTY_GROUP_MEMBERS [MPMAS TABLES].\nThis is required because COMMON_PROPERTY has been set to 1)\n"  and exit(1) unless (defined $self->config_entry("COMMON_PROPERTY_GROUP_MEMBERS"));

	$self->{common_property} = $self->config_entry("COMMON_PROPERTY_GROUP_MEMBERS")->transform($self->get_dbh(),2);

}
sub prepare_special {
	my ($self) = @_;
	
	my $common = MpmasInputBlock->new(3,10);
	$common->add_row("","COMMON PROPERTY AREAS");

	my @grouplist = sort {$a <=> $b} $self->{common_property}->query([],0);

	$common->add_row("","","Number of groups", scalar (@grouplist) );

	for my $g (@grouplist) {
		$common->add_row("","","Group ID:", $g );	
		my @memberlist = sort {$a <=> $b} $self->{common_property}->query([$g],0);	
		$common->add_row("","","Members:", @memberlist );
		$common->add_row("","","", "#END_LIST_PART" );
		
	}
	$self->add_block($common);
}

1;
