#------------------------------------------------------------
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::DB::Item::ReportConfig;
use strict;
use warnings;

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

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

use constant kTable => 'report_config';
use constant kDB    => Common::DB::Item::kClientDB;

use constant kTYPE_TEXT    => 'text';
use constant kTYPE_EXCEL   => 'excel';
use constant kCOL_SPLITTER => ',';
use constant kMAP_KEY      => 'report_config_id';
use constant kMAP_VAL      => 'name';

sub mapKey { return kMAP_KEY }
sub mapVal { return kMAP_VAL }

# pass array ref to set
# receive array ref for get
sub columns {
    my ( $self, $cols ) = @_;

    if ( ref($cols) eq 'ARRAY' )    # set
    {
        my $colStr = join( kCOL_SPLITTER, @$cols );
        $self->SUPER::columns($colStr);

        return 1;
    }

    # else - get
    my $split = kCOL_SPLITTER;
    my @cols = split( /$split/, $self->SUPER::columns() );

    return \@cols;
}

sub GetAllSortedByName {
    my $class = shift;

    return $class->SUPER::GetAll( 'SELECT * FROM ' . kTable . ' ORDER BY is_default DESC, name' );
}

sub GetDefaultConfig {
    my ($class) = @_;

    return $class->Lookup( is_default => 'Y' );
}

1;
