package RPS::Import::Sainsburys::v1;

use strict;

use lib '/app/tools/common/lib';
use Common::Date;

use lib '/app/tools/rps/lib';
use base 'RPS::Import::Importer';

use Data::Dumper;

sub _headerIdentifier { ( upc => 'PRODUCT_UPC' ) }

sub _fieldMap {
    {
        dateBegin        => 'J',
        countryCode      => 'H',
        formatType       => 'G',
        artistName       => 'D',
        upc              => 'B',
        albumName        => 'E',
        isrc             => 'A',
        trackName        => 'E',
        units            => 'K',
        currencyCode     => 'I',
        price            => 'M',
    }
}

sub productType {
    my $self = shift;
    my $isrc = $self->_getByFieldName('isrc');
    my $upc  = $self->_getByFieldName('upc');
    if( $isrc && '' ne $isrc )
    {
        return RPS::File::Sale::TYPE_TRACK;
    }
    elsif( $upc && '' ne $upc )
    {
        return RPS::File::Sale::TYPE_ALBUM;
    }
    $self->fail( "Unable to determine product type" );
}

sub formatType  {
    my $self = shift;
    my $format = $self->_getByFieldName('formatType') || return;

    if( $format =~ /^(16|17|18|23)$/i )
    {
        return RPS::File::Sale::FORMAT_STREAM;
    }
    elsif( $format =~ /^4$/i )
    {
        return RPS::File::Sale::FORMAT_RINGTONE;
    }
    elsif( $format =~ /^3$/i )
    {
        return RPS::File::Sale::FORMAT_DOWNLOAD;
    }

    $self->fail( "Unknown format type '$format'" );
}

sub albumName {
    my $self = shift;
    my $title = $self->_getByFieldName('albumName') || return;
    return ( $self->productType eq RPS::File::Sale::TYPE_ALBUM ) ? $title : undef;
}

sub trackName {
    my $self = shift;
    my $title = $self->_getByFieldName('trackName') || return;
    return ( $self->productType eq RPS::File::Sale::TYPE_TRACK ) ? $title : undef;
}

sub mediaType {
    my $self = shift;
    return RPS::DB::Item::MediaType::kMediaTypeAudio;
}

###
1;# Play nicely.
###
