#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#---------------------------------------------------------------
package BookPub::Catalog::ContributorRole;
use strict;
use warnings;

use lib '/app/tools/common/lib';
use lib '/app/tools/bookpub/lib';
use BookPub::DB::Item::ContributorRole;
use Common::RSApp;
use Common::Util;
use Common::Assert;
use Common::FormObject;

use base 'Common::FormObject';

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

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

    my %properties;
    if ( $args{dbItem} ) {
        $self->_propertiesFromDBItem( \%properties, $args{dbItem} );
    } elsif ( $args{contributorRoleID} ) {
        $self->_propertiesFromDB( \%properties, $args{contributorRoleID} );
    } else {
        $self->_propertiesFromDefaults( \%properties );
    }

    $self->_initProperties( \%properties );

    return $self;
}

sub _propertiesFromDB {
    my ( $self, $hrProperties, $id ) = @_;

    my $dbItem = BookPub::DB::Item::ContributorRole->Lookup( contributor_role_id => $id );

    $self->_propertiesFromDBItem( $hrProperties, $dbItem );
}

sub _propertiesFromDBItem {
    my ( $self, $hrProperties, $dbItem ) = @_;

    $hrProperties->{contributor_role_id} = $dbItem->contributor_role_id;
    $hrProperties->{onix_code}           = $dbItem->onix_code;
    $hrProperties->{description}         = $dbItem->description;

}

sub _initProperties {
    my ( $self, $props ) = @_;

    # Not editable...
    $self->{ContributorRoleID} = $props->{contributor_role_id};

    $self->{ONIXCode}    = Common::FormObject::Scalar::String->new( value => $props->{onix_code} );
    $self->{Description} = Common::FormObject::Scalar::String->new( value => $props->{description} );
}

sub _propertiesFromDefaults {
    my ( $self, $hrProperties ) = @_;
}

###
1;    #
###
