package MpmasSegmentSet;

use strict;
use warnings;
use Exporter;
use Storable qw(dclone);
use Data::Dumper;
use SimpleObjectRegistry;
use MpmasInputBlock;
use SimpleObject;
use IndexedTable;
use MpmasSegment;
use CtUtilities qw(queryhash strip_sql);
our @ISA = qw(MpmasInputfileSet);

sub class_of_files{
	return "MpmasSegment";
 }

sub determine_files {
	my $self = shift;
	for my $n (0..$self->config_entry("NETWORKS")- 1 ) { 
		for my $s (0..$self->config_entry("SEGMENTS")- 1 ) {
			my $fname = "$n"."_"."$s";
			$self->add_file($fname,$fname);
		}
	}
}

sub prepare_shared_files {
	my $self = shift;
	my $dbh = $self->get_dbh;
	if (defined $self->config_entry("SEGINFO")) {
		$self->{seginfo} = $self->config_entry("SEGINFO")->transform($dbh,3); 
	}
	if ($self->config_entry("PERMCROP_MODEL") == 1 and defined $self->config_entry("SEGBOUNDS")) {
		$self->{segbounds} = $self->config_entry("SEGBOUNDS")->transform($dbh,3);	
	}
	elsif ($self->config_entry("PERMCROP_MODEL") == 0 and defined $self->config_entry("STANDARD_LAND_RENTS")) {
		$self->{segbounds} = $self->config_entry("STANDARD_LAND_RENTS")->transform($dbh,3);	
	}
	$self->{thresholds} = [$self->get_cfg_list("THRESHOLDS")];
}

sub prepare_special_files {
	my $self = shift;
	for my $f ($self->files) {
		$f->prepare_special(  $self->{thresholds}, $self->{seginfo} , $self->{segbounds});
	}
}
1;
