package RPS::Import::Curve::v3;

use strict;
use warnings;

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

use base 'RPS::Import::Curve::v2';

sub physical { 2 }

sub _fieldMapExtended {
    {
        mixed => {
            option1 => {
                countryCode     => 'H',
                dateBegin       => 'D',
                formatType      => 'V',
                clientProductID => 'J',
                upc             => 'I',
                albumName       => 'K',
                isrc            => 'P',
                trackName       => 'Q',
                units           => 'X',
                priceLevel      => 'W',
                currencyCode    => 'AY',
                totalRevenue    => 'AT',
                price           => 'AT',
                mediaType       => 'V',
            }
        }
    };
}

sub _unverifiedFieldMapExtended {
    {
        mixed => {
            option1 => {
                _productTypePhys   => 'V',
                _productTypeDig    => 'B',
                _releaseArtistName => 'M',
                _trackArtistName   => 'S',
                _netUnits          => 'X',
                _distChannel       => 'U',
                # we should use the allowed field names or add new ones to
                # /app/tools/rps/templates/mapface/map.xsl
                service            => 'F', # physical
                retailer           => 'E', # digital
            }
        }
    };
}

sub _headerIdentifierExtended {
    {
        mixed => {
            option1 => { upc => 'Barcode' },
        },
    };
}

sub currencyCode {
    my $self = shift;

    my $code = $self->_getByFieldName('currencyCode') || '';
    $code =~ /^(\w{3})$/;

    return $1 if $1;

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

sub _isValidSaleRecord {
    my $self = shift;

    my $distChannel = $self->_getByFieldName('_distChannel') || '';
    if ( $distChannel =~ /^Sync(?:hronization)?$/i ) {
        $self->fail("The sync sale cannot be processed.");
    }

    return $self->SUPER::_isValidSaleRecord(@_);
}


1;
