package RPS::Import::Inertia::v1;

use strict;
use warnings;

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

use parent 'RPS::Import::ImporterMixed';

sub physical { 2 }

sub _fieldMapExtended {
    {
        digital => {
            option1 => {
                countryCode  => 'E',
                dateBegin    => 'F',
                dateEnd      => 'F',
                productType  => 'I',
                formatType   => 'V',
                upc          => 'A',
                albumName    => 'C',
                isrc         => 'A',
                trackName    => 'D',
                units        => 'Q',
                currencyCode => 'S',
                price        => 'R',
            },
         },
    };
}

# We need this method exists in order to fit mixed Interface
sub _unverifiedFieldMapExtended {{ }}

sub _headerIdentifierExtended {
    {
        digital => {
            option1 => {
                upc => 'Product Code',
            },
        },
    };
}

sub serviceID { Client::Service::DSP_INERTIA; } 

sub countryCode {
    my $self = shift;

    my $name = $self->_getByFieldName('countryCode') || '';
    my $oCountry = Common::Country->Get($name);
    return $oCountry ? $oCountry->alpha2 : undef ;
}

sub saleDates {
    my $self = shift;

    my $dt = $self->_getDateBegin() || '';
    
    return $self->_getDates( date_begin => $dt, type => 'eur' );
}

sub productType {
    my $self = shift;

    my $type = $self->_getByFieldName('productType') || '';
    if ( $type =~ /^ad$/i ) {
        return RPS::File::Sale::TYPE_ALBUM;
    } elsif ( $type =~ /^td$/i ) {
        return RPS::File::Sale::TYPE_TRACK;
    }

    $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 < 0.20;
    return RPS::File::Sale::FORMAT_DOWNLOAD if $type >= 0.20;

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

sub upc {
    my $self = shift;
    
    return $self->_getByFieldName('upc') if ($self->productType() eq RPS::File::Sale::TYPE_ALBUM);
}

sub isrc {
    my $self = shift;
    
    return $self->_getByFieldName('isrc') if ($self->productType() eq RPS::File::Sale::TYPE_TRACK);
}

sub mediaType { RPS::DB::Item::MediaType::kMediaTypeAudio }

1;
