package RPS::Import::Sony::SMEPreProc;

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;

# okay, this may pretend to be looking like a base class importer
# for something meaningful going forward, but it's really just a hack
# that i threw together so that we could import what appear to be
# spotify sales in sme's preproc format. something real (and generic
# to preproc) would actually not force product and format types
# (or country codes for that matter)
#
# in the big picture i don't really see a future for this importer
# (and we're only doing it now for an *EMI* demo), but i've lost
# track of the future.
#
# for a list of suspects, see scott holcombe, bob kohn and
# damon sheerin (and jeff jengo maybe)

sub _fieldMap {
    {
        # Header
        currencyCode => 'E',

        # Data
        dateBegin  => 'I',
        dateEnd    => 'J',
        artistName => 'P',
        upc        => 'L',
        albumName  => 'Q',
        isrc       => 'M',
        trackName  => 'R',
        units      => 'AE',
        price      => 'Z',
    };
}

sub _unverifiedFieldMap {
    { recordType => 'A', };
}

sub _headerIdentifier { ( recordType => 'A' ) }

sub _processHeader {
    my $self = shift;
    my $currencyCode = $self->SUPER::currencyCode || return;

    return if ( $self->{_currencyCode} );

    $self->{_currencyCode} = $currencyCode if ( $currencyCode =~ /^\w{3}$/ );
}

sub _productTypes { undef }

sub currencyCode { shift->{_currencyCode} }

sub countryCode { 'SE' }

sub formatType { RPS::File::Sale::FORMAT_STREAM }

sub productType { RPS::File::Sale::TYPE_TRACK }

sub upc {
    my $idfield = shift->SUPER::upc;

    my ($upc) = $idfield =~ m/^(\d*)\s*/;

    return $upc;
}

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