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

# !!! THIS IS DEPRECATED

use strict;
use warnings;

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

use Common::DB::Item;
use base 'Common::DB::Item';

use constant kTable => 'artist_contract_region';

my $gConfig =
{
	_db => Common::DB::Item::kClientDB(),

	'artist_contract_region_id' =>
	{
		_table => kTable,
		_auto => 1,
		_key => 1,
	},
	'artist_contract_id' =>
	{
		_table => kTable,
	},
	'contract_mode' =>
	{
		_table => kTable,
	},
	'region_id' =>
	{
		_table => kTable,
	},
	'percent' =>
	{
		_table => kTable,
	},
};


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

	return $gConfig;
}



sub GetByArtistContractID
{
	my ($contractID, $mode) = @_;
	assert($contractID);

	# my $dbo = Common::RSApp::GetClientDB();
    my $where = "WHERE artist_contract_id=$contractID";
    if ($mode)
    {
        $where .= " AND contract_mode=$mode";
    }

	my $sql = "SELECT * FROM artist_contract_region $where ORDER BY artist_contract_region_id";

	my $collection = Common::DB::ItemCollection->new(
	 class => "RPS::DB::Item::ArtistContractRegion",
	 query => $sql,
	 dbID => $gConfig->{_db},
	);

	return $collection;
}


sub GetByRegionID
{
    my ($regionID) = @_;
	assert(defined $regionID);

    my $sql = "SELECT * from artist_contract_region WHERE region_id=$regionID";

	my $collection = Common::DB::ItemCollection->new(
	 class => "RPS::DB::Item::ArtistContractRegion",
	 query => $sql,
	 dbID => $gConfig->{_db},
	);

	return $collection;
}

sub GetByContractRegion
{
    my ($contractID, $regionID) = @_;
	assert($contractID);
	assert(defined $regionID);

    my $sql = "SELECT * from artist_contract_region WHERE artist_contract_id=$contractID AND region_id=$regionID";

	my $collection = Common::DB::ItemCollection->new(
	 class => "RPS::DB::Item::ArtistContractRegion",
	 query => $sql,
	 dbID => $gConfig->{_db},
	);

	return $collection;
}

1;

