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

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

use lib '/app/tools/rps/lib';
use RPS::Song::Song;
use RPS::Master::Master;
use RPS::Song::ComposerList;

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

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

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

	if ($args{songID})
	{
		$self->{Song} = RPS::Song::Song->new(songID => $args{songID});

		# find associated masters
		#
		my $masters;
		$masters = RPS::DB::Item::Master->GetMastersBySongID($args{songID});

		if(defined $masters && $masters->size > 0)
		{
			while ($masters->hasNext())
			{
				my $masterObj = $masters->next();

				push @{$self->{MasterList}{Master}}, RPS::Master::Master->new(_dbItem => $masterObj, loadSubs => 0);
			}
		}
	}
	else
	{
		$self->{Song} = RPS::Song::Song->new();
	}

	$self->{ComposerList} = RPS::Song::ComposerList->new();

	return $self;
}

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

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

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

	# JPK - This is one of those situations where I _don't_ want to
	# validate everything this object contains.  It's a waste of time
	# to validate the <Song>, for example, since we don't support making
	# changes to it.
	#
	my $valid = $self->{Song}->validate();

	return $valid;
}


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

	# my $userID = Common::RSApp::GetActiveUserID();

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


sub songID
{
	my ($self) = @_;
	return $self->{Song}->SongID();
}


###
1;#
###
