package MpmasStataLabelsP;

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

sub filename {
	return "StataLabelsP";
}

sub write {
	my $self = shift;
	print "\e[K \r";
	print "Writing STATA Performance label file...\r";
	open(my $klabout, ">",  $self->outdir.$self->mname."_p_labels.do") or die "Can't open ". $self->outdir.$self->mname."_p_labels.do $!";
	print $klabout <<HD_KLABEL;
label var v1 "typ_str"
label var v2 "aID"
label var v3 "catchID"
label var v4 "secID"
label var v5 "fstID"
label var v6 "popID"
label var v7 "clustID"
label var v8 "nwID"
label var v9 "segID"
label var v10 "expectID"
label var v11 "colorID"
label var v12 "xcoord"
label var v13 "ycoord"
label var v14 "numplots"
HD_KLABEL

	my @performancelabels = ("TotalGrossMargin", "Cashflow", "Income",
					"ValueAdded", "EquityCapital", "PaymentToLand",
					"RelativeFactorPayments", "OnFarmLabor", "OnFarmCapital",
					"InterestsPaid", "DistanceCosts",
					"AdditionalTransportCosts", "WithdrawalsForConsumption",
					"LiquidMeans", "MigrationDecision",
					"LastLpSolved", "FixCosts",
					"TranspCosts", "Deposits", "Depreciation",
					"LiqMeansUsedForInvestment", "PrincipalPaid", "DebtCapital", "ExpRemainingLifetime", "AgeHHead", "RentalPayments", "GrossInvestments", "AssetSales");

	if( $self->config_entry("CONSTYPE") == 1) {
		@performancelabels = ("HouseholdIncome", "NetCashEarningsFromMILP", "NetInKindEarningsFromMILP",
					"AppreciationOfDurableAssets", "DepreciationOfDurableAssets", "Savings", "ExtraConsumption",
					"TotalConsumption", "ValueAdded", "EquityCapital", "PaymentToLand", "RelativeRactorPayment",
					"OnFarmLabor", "OnFarmCapital", "InterestsPaid", "DistanceCosts", "AdditionalTransportCosts",
					"NumberOfMaleAdults", "NumberOfFemaleAdults", "NumberOfMaleChildren", "NumberOfFemaleChildren",
					"WithdrawalsForConsumption", "LiquidMeans", "MigrationDecision", "LastLpSolved(inv=1,prd=2,con=3)", "DebtCapital");
	}
	for my $i (0..$#performancelabels) {
			print $klabout  "label var v" . (15 + $i) . " \"".$performancelabels[$i] ."\"\n";
	}
	close $klabout;

}

1;
