package RPS::Import::Anghami::v1;

use strict;
use warnings;

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

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

sub physical { 0 }

sub _fieldMapExtended {
    {
        digital => {
            option1 => {
                labelName   => 'D',
                countryCode => 'A',
                dateBegin   => 'L',
                dateEnd     => 'L',
                productType => 'C',
                artistName  => 'I',
                upc         => 'G',
                albumName   => 'H',
                isrc        => 'E',
                trackName   => 'F',
                units       => 'K',
                price       => 'M',
            },
         },
    };
}

sub _unverifiedFieldMapExtended { {} }

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


sub currencyCode { 'USD' }
sub serviceID    { Client::Service::DSP_ANGHAMI }
sub mediaType    { RPS::DB::Item::MediaType::kMediaTypeAudio }
sub formatType   { RPS::File::Sale::FORMAT_STREAM }

sub countryCode {
    my $self = shift;

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

sub productType {
    my $self = shift;

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

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

sub units {
    my $self = shift;

    my $units = $self->_getByFieldName('units') || 0;
    my $price = $self->_getByFieldName('price') || 0;

    if ( $price > 0 ) {
        $units = $units ? abs($units) : 1;
    } elsif ( $price < 0 ) {
        $units = $units ? -1 * abs($units) : -1;
    }

    return $units;
}


1;