package RPS::Import::MusicKey;

use strict;

use Data::Dumper;
use lib '/app/tools/common/lib';
use Common::Util qw(normalize_upc normalize_isrc);
use Date::Calc qw(Days_in_Month);

use lib '/app/tools/data_classes/lib';

use lib '/app/tools/rps/lib';
use RPS::File::Sale;
use base 'RPS::Import::Importer';

sub _headerIdentifier { ( isrc => 'ISRC' ) }

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        1 => {
            countryCode => 'J',
            dateBegin   => 'I',
            dateEnd     => 'I',
            artistName  => 'G',
            upc         => 'F',
            ,
            isrc      => 'C',
            trackName => 'H',
            units     => 'O',
        },
    );

    return $fieldMap{ $self->_version() };
}

sub mediaType    { RPS::DB::Item::MediaType::kMediaTypeAudio }
sub productType  { RPS::File::Sale::TYPE_TRACK }
sub formatType   { RPS::File::Sale::FORMAT_STREAM }
sub currencyCode { 'USD' }

sub _isValidSaleRecord {
    my $self = shift;

    # The line is valid if it has units.
    #
    my $units = $self->units;
    if ($units) {

        # Let's make sure we have some kind of identifier.
        if ( $self->isrc || $self->trackName ) {
            return 1;
        } else {
            $self->fail("Missing Track Name and ISRC");
        }
    }

    return;
}

###
1;    # Play nicely.
###
