package MpmasNetworkObject;
use strict;
use warnings;
use Exporter;
use Storable qw(dclone);
use Data::Dumper;
use MpmasQLModelElementAbstract;

our @ISA = qw(MpmasQLModelElementAbstract);

##class variables
my %existing_onames;

##implmentation of MpmasQLModelElements abstract methods
sub defaultclass {
	"asset"
}
sub list_of_default_fields { 
	my @array = qw(name innogrp type div acqcost lifetime terrain mininvest	act con perm multiplier	innovativeness	eqshare	irate landreq available_until_period inflation_rate_past minimum_age_at_simulation_start maximum_age_at_simulation_start resale_share resale_book_share disinvest_completely plot_capacity_layer plot_capacity_used can_be_attached_to_rented_land compensation_when_returning_with_rented_land resale_topup resale_topup_reduction_per_year_of_age is_livestock internal_accounting is_perennial);
	return \@array;
}
sub list_of_attribute_fields{
	my @array = qw(othermilp othermilp_subelements name description innogrp type div acqcost lifetime terrain mininvest act con perm multiplier innovativeness eqshare irate oname landreq oid available_until_period sex inflation_rate_past minimum_age_at_simulation_start maximum_age_at_simulation_start resale_share resale_book_share disinvest_completely plot_capacity_layer plot_capacity_used can_be_attached_to_rented_land compensation_when_returning_with_rented_land resale_topup resale_topup_reduction_per_year_of_age new_asset_sparked_at_end_of_life new_asset_sparked_when_disinvested is_livestock internal_accounting offspring_at_age offspring_probability is_perennial) ;
	return \@array;
}
sub list_of_attribute_stubs {
	my @array = qw();
	return \@array;
}
sub calculate_attributes {
	my $self = $_[0];
	my $oname = $self->{oname};
	if (not defined $oname) {
	     $oname  = $self->id;
	}
	if (length($oname) > 10) {
	     $oname = substr($oname,0,10);
	}
	if (exists $existing_onames{$oname}) {
	     $oname = substr($oname,0,5) . sprintf("%05d", scalar(keys(%existing_onames) ));
	}
	$existing_onames{$oname} = 1;
	$self->{oname} = $oname;
	
}
sub reset_existing_onames {
  undef %existing_onames ;
}

my %defaults = (
	name	=>	"N/A",
	innogrp	=>	"none",
	type	=>	1,
	div		=>	1,
	acqcost	=>	0,
	lifetime =>	1,
	terrain	=>	-1,
	mininvest	=> 0,
	is_livestock	=> 0,
	act	=>	"a1",
	con	=>	"c1",
	perm	=>	-1,
	multiplier	=>	1,	
	innovativeness => 4	,
	landreq	=>	0,
	available_until_period	=>	 1000,
	inflation_rate_past	=>	0,
	minimum_age_at_simulation_start => 1,
	maximum_age_at_simulation_start => 1000,
	resale_share =>	0.0,
	resale_book_share => 0.0,
	resale_topup		=>	0,
	resale_topup_reduction_per_year_of_age	=> 0,
	disinvest_completely	=>	0,
	plot_capacity_layer		=>	-1,
	plot_capacity_used		=>	0.0,
	can_be_attached_to_rented_land	=>	0,
	compensation_when_returning_with_rented_land => 0,
	internal_accounting => 1,
);
sub get_default_value {
	return $defaults{$_[1]};
}
sub set_default_value {
	$defaults{$_[1]} = $_[2] ;
}
##additional class methods
sub set_oid {
	my $self = shift;
	my $var = shift;
	$self->{oid} = $var;
}
sub oid {
	my $self = shift;
	return 	$self->{oid} if (exists $self->{oid} );
    return $self->get_default_value("oid") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}
sub set_con {
	my $self = shift;
	my $var = shift;
	$self->{con} = $var;
}
sub con {
	my $self = shift;
	return 	$self->{con} if (exists $self->{con} );
    return $self->get_default_value("con") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}
sub set_act {
	my $self = shift;
	my $var = shift;
	$self->{act} = $var;
}
sub act {
	my $self = shift;
	return 	$self->{act}if (exists $self->{act} );
    return $self->get_default_value("act") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}
sub set_perm {
	my $self = shift;
	my $var = shift;
	$self->{perm} = $var;
}
sub perm {
	my $self = shift;
	return 	$self->{perm}if (exists $self->{perm} );
    return $self->get_default_value("perm") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}
sub set_type {
	my $self = shift;
	my $var = shift;
	$self->{type} = $var;
}
sub type {
	my $self = shift;
	return 	$self->{type} if (exists $self->{type} );
    return $self->get_default_value("type") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}
sub set_innogrp {
	my $self = shift;
	my $var = shift;
	$self->{innogrp} = $var;
}
sub innogrp {
	my $self = shift;
	return 	$self->{innogrp} if (exists $self->{innogrp} );
    return $self->get_default_value("innogrp") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}
sub set_innovid {
	my $self = shift;
	my $var = shift;
	$self->{innovid} = $var;
}
sub innovid {
	my $self = shift;
	return 	$self->{innovid} if (exists $self->{innovid} );
    return $self->get_default_value("innovid") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}
sub set_srank {
	my $self = shift;
	my $var = shift;
	$self->{srank} = $var;
}
sub srank {
	my $self = shift;
	return 	$self->{srank} if (exists $self->{srank} );
    return $self->get_default_value("srank") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}
sub set_network_row {
	my $self = shift;
	my $var = shift;
	$self->{NetworkRow} = $var;
}
sub network_row {
	my $self = shift;
	return 	$self->{NetworkRow} if (exists $self->{NetworkRow} );
    return $self->get_default_value("NetworkRow") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}

sub set_ifnet {
	my $self = shift;
	my $var = shift;
	$self->{ifnet} = $var;
}
sub ifnet {
	my $self = shift;
	return 	$self->{ifnet} if (exists $self->{ifnet} );
    return $self->get_default_value("ifnet") unless ($MpmasQLModelElementAbstract::donotsetdefaults);
}

1;
