package RPS::Import::Dorado::v3;

use strict;
use warnings;

use lib '/app/tools/rps/lib';

use RPS::Import::ServiceMap;
use Date::Calc qw(Days_in_Month);

use parent qw/RPS::Import::Dorado::v2/;

sub physical { 0 }

sub _fieldMapExtended {
    {
        digital => {
            option1 => {
                labelName   => 'H',
                serviceID   => 'K',
                countryCode => 'O',
                productType => 'I',
                formatType  => 'I',
                artistName  => 'M',
                upc         => 'D',
                isrc        => 'F',
                trackName   => 'N',
                units       => 'P',
                price       => 'T',
                mediaType   => 'I',
            }
        }
    }
}

sub _unverifiedFieldMapExtended {
    {
        digital => {
            option1 => {
                _year  => 'A',
                _month => 'B',
            }
        }
    }
}

sub _headerIdentifierExtended {
    {
        digital => {
            option1 => { artistName => 'Artist' }
        }
    }
}

sub productType {
    my $self = shift;

    my $type = $self->_getByFieldName('productType') || '';

    return RPS::File::Sale::TYPE_TRACK if $type =~ /^Art Track$/i;
    $self->fail("Unable to determine product type from: '$type'");
}

sub formatType {
    my $self = shift;

    my $type = $self->_getByFieldName('formatType') || '';

    return RPS::File::Sale::FORMAT_STREAM if $type =~ /^Art Track$/i;
    $self->handleError( "Unknown format type: $type", RPS::DB::Item::SaleImportError::kErrorFormatType );
}

sub mediaType {
    my $self = shift;

    my $type = $self->_getByFieldName('mediaType') || '';

    return RPS::DB::Item::MediaType::kMediaTypeAudio;
    $self->fail("Unable to determine media type from: '$type'");
}

sub _isValidSaleRecord {
    my $self = shift;

    my $units = $self->units;
    my $price = $self->price;
    my $lineNum = $self->linenum;

    # print STDERR "HHH => Line: $lineNum, Units: '$units', Price: '$price'\n";
    return $units * 1 || $price * 1 ? 1 : 0;
}


1;
