#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Mechanical::UK::McpsLicenseForm;

use strict;
use warnings;
use Data::Dumper;

use lib '/app/tools/common/lib';
use Common::Assert;

use lib '/app/tools/rps/lib';
use RPS::DB::Item::Payor;
use RPS::Catalog::AlbumSimple;
use RPS::Payor::PayorList;
use RPS::Price::PriceList;
use RPS::Price::PriceLevelList;
use RPS::Product::Product;
use RPS::Product::StatusList;
use RPS::Product::TypeList;
use RPS::Track::Track;
use RPS::Mechanical::UK::McpsLicense;
use RPS::RoyaltyRun::RoyaltyRunStatusList;

use Common::FormObject;
use base 'Common::FormObject';

sub _init
{
	my ($self, %args) = @_;

	$self->SUPER::_init(%args);

    my $mcpsLicense;

	if ($args{productID})
    {
		$mcpsLicense = RPS::Mechanical::UK::McpsLicense->new(
            productID => $args{productID}
        );

	}


    my $product = RPS::Product::Product->new(productID => $args{productID});

    $self->{McpsLicense} = $mcpsLicense;
    $self->{Album} = RPS::Catalog::AlbumSimple->new(albumID => $product->AssetID());
    $self->{Product} = $product;
    $self->{PriceList} = RPS::Price::PriceList->new();
    $self->{PriceLevelList} = RPS::Price::PriceLevelList->new();
    $self->{StatusList} = RPS::Product::StatusList->new();
	$self->{TypeList} = RPS::Product::TypeList->new();
	$self->{PayorList} = RPS::Payor::PayorList->new();

	my $defaultPayor = RPS::DB::Item::Payor->GetDefault();
	if ($defaultPayor)
	{
		$self->{DefaultPayorID} = $defaultPayor->payor_id;
	}

	$self->{RoyaltyRunStatus} = new RPS::RoyaltyRun::RoyaltyRunStatusList( ukMechanical => 1 );

	return $self;
}

sub _propertyIsEditable
{
	my ($self, $propertyName) = @_;

	# The McpsLicense (and contained objects) can be edited.
	#
	if ($propertyName eq 'McpsLicense')
	{
		return 1;
	}
	return 0;
}

# This method may not be necessary (the inherited validate should invoke McpsLicense::validate automatically)
#
sub validate
{
	my ($self, $skipRequiredFields) = @_;

	my $valid = $self->{McpsLicense}->validate($skipRequiredFields);

	return $valid;
}


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

	$self->{McpsLicense}->save();
}


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

	return $self->{McpsLicense}->McpsLicenseID();
}


###
1;#
###
