package RPS::Import::Mtheory::v4;

use strict;
use warnings;

use lib '/app/tools/rps/lib';
use RPS::Import::ServiceMap;

use parent 'RPS::Import::Mtheory::v3';

sub _fieldMapExtended {
    {
        digital => {
            option1 => {
                labelName   => 'J',
                serviceID   => 'R',
                countryCode => 'F',
                dateBegin   => 'E',
                productType => 'M',
                formatType  => 'L',
                artistName  => 'B',
                upc         => 'W',
                albumName   => 'A',
                isrc        => 'I',
                trackName   => 'T',
                units       => 'V',
                price       => 'P',
                mediaType   => 'K',
            },
         },
    };
}

sub _unverifiedFieldMapExtended {{}}
sub _headerIdentifierExtended {
    {
        digital => {
            option1 => {
                upc => 'upc_ean',
            },
        },
    };
}

sub saleDates {
    my $self = shift;

    my $date = $self->_getByFieldName("dateBegin");

    my ( $dateBegin, $dateEnd ) = $self->_getDates( date_begin => $date, type => 'iso' );
    return ($dateBegin, $dateEnd) if ($dateBegin);

    $self->fail( "Unable to determine date from: '$date'." );
}

sub countryCode {
    my $self = shift;

    my $name = $self->_getByFieldName('countryCode') || '';

    return "ZZ" if $name =~ /^row$/i;

    my $country = Common::Country->Get($name) if $name;

    return $country
        ? $country->alpha2
        : $self->fail("Unable to determine country_code from: '$name'.");
}

1;
