package RPS::Import::NewDay::v2;

use strict;
use warnings;

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

use parent 'RPS::Import::NewDay::v1';

sub physical { 1 }

sub _fieldMapExtended {
    {
        physical => {
            option1 => {
                labelName    => 'E',
                countryCode  => 'J',
                dateBegin    => 'A',
                dateEnd      => 'A',
                productType  => 'D',
                artistName   => 'C',
                upc          => 'B',
                albumName    => 'D',
                retailPrice  => 'G',
                totalRevenue => 'I',
                mediaType    => 'D',
            },
        },
    };
}

sub _unverifiedFieldMapExtended {
    {
        physical => {
            option1 => {
                _netUnits => 'F',
            },
        }
    };
}

sub _headerIdentifierExtended {
    {
        physical => {
            option1 => {
                upc => 'UPC',
            },
        },
    };
}

sub currencyCode  { 'USD' }
sub serviceID     { Client::Service::DSP_NEW_DAY }
sub channel       { RPS::File::Sale::CHANNEL_RETAIL }
sub priceLevel    { RPS::File::Sale::PLEVEL_UNKNOWN }
sub mediaType     { RPS::DB::Item::MediaType::kMediaTypeAudio }

sub productType {
    my $self = shift;

    my $productType = $self->_getByFieldName('productType') || '';
    my ($type) = $productType =~ /^\((\w+)\)/;

    return RPS::File::Sale::TYPE_CD  if $type =~ /^CD$/i;
    return RPS::File::Sale::TYPE_LP  if $type =~ /^(?:LP|EP|)$/i;
    return RPS::File::Sale::TYPE_DVD if $type =~ /^DV$/i;

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

sub countryCode {
    my $self = shift;

    my $country = $self->_getByFieldName('countryCode') || '';
    my $o = Common::Country->Get($country) if $country;
    return $o->alpha2 if $o;

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


1;