#---------------------------------------------------------------
# ____                   _ _         ____  _
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/
#
# Copyright (C) 2011 RoyaltyShare, Inc.   All Rights Reserved
#---------------------------------------------------------------

package RPS::Report::Dynamic::Catalog::Base;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use lib '/app/tools/report/lib';
use lib '/app/tools/rps/lib';
use lib '/app/tools/appuser/lib';

use Common::Log;
use Common::Assert;
use Common::Client;
use File::Path;
use AppUser::DB::Item::AccessLevel;
use Report::Dynamic::Parameters;

use base 'Report::Dynamic::SingleQuery';

#
# Really just want to move some of the formatting methods into a common place.
# I thought about creating a base RPS::Report::Dynamic class, but I don't want
# to _assume_ that every sort of report will inherit from SingleQuery.
#
# But anything that requires 'RPS' data should NOT be moved into the Report namespace.
#


sub Group   { 'Catalog'; }

sub UserLevelIsValid
{
    my ($class, $userLevel) = @_;
    my %validLevels = (
        AppUser::DB::Item::AccessLevel::kRSAdmin() => 1,
        AppUser::DB::Item::AccessLevel::kRSAccountRep() => 1,
        AppUser::DB::Item::AccessLevel::kAdmin() => 1,
        AppUser::DB::Item::AccessLevel::kRoyalty() => 1,
        AppUser::DB::Item::AccessLevel::kAdminCatalogView() => 1,
        AppUser::DB::Item::AccessLevel::kCatalogOnly() => 1,
    );

    return $validLevels{$userLevel};
}


sub ClientTypeMask { return Common::Client::kDigitalAdvantage; }

sub _secondsFromDuration
{
    my ($self, %args) = @_;
    my $rowItem = $args{row};
    my $fieldName = $args{field};


    my $totalSeconds = $rowItem->$fieldName();
    return 0 unless $totalSeconds;
    return int($totalSeconds % 60);
}

sub _minutesFromDuration
{
    my ($self, %args) = @_;
    my $rowItem = $args{row};
    my $fieldName = $args{field};


    my $totalSeconds = $rowItem->$fieldName();
    return 0 unless $totalSeconds;
    return int($totalSeconds / 60);
}



1;
