package BookPub::Import::Importer::NEMCC::v1;

use strict;
use warnings;

use lib '/app/tools/bookpub/lib';
use parent 'BookPub::Import::Importer';

sub _fieldMap {
    {
        rServiceName         => 'G',
        dateBegin            => 'B',
        dateEnd              => 'B',
        rProductType         => 'R',
        priceType            => 'AD',
        rAuthor              => 'Z',
        rTitle               => 'Y',
        rIsbn13              => 'W',
        rInstitution         => 'G',
        rState               => 'I',
        rPostalCode          => 'H',
        countryCode          => 'J',
        serviceProductID     => 'X',
        rUnits               => 'AC',
        rUnitPrice           => 'AH',
        rListPrice           => 'AE',
        rListPriceCurrency   => 'AG',
        rRevenue             => 'AF',
        currencyCode         => 'AK',
        rTaxAmount           => 'AJ',
        rFee                 => 'AI',
        rDuration            => 'AB',
        rDeliveryMethod      => 'K',
        rTransactionCategory => 'C',
    };
}

sub _headerIdentifier { rTitle => 'TITLE' }

sub _useIsSaleRec { 1 }
sub rProductType  { $_[0]->productType }
sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeLoan }

sub rServiceName {
    my $self = shift;

    my $name = $self->_getByFieldName('rServiceName') || '';
    if ( $name =~ /^Northeast Mississippi Community College$/i ) {
        return 'NEMCC';
    }

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

sub productType {
    my $self = shift;

    my $type = $self->_getByFieldName('rProductType') || '';
    return BookPub::DB::Item::Sale::kProductTypeEBook if $type =~ /^book$/i;

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

sub priceType {
    my $self = shift;

    my $type = $self->_getByFieldName('priceType') || '';
    return 'rrp' if $type =~ /^(?:Custom|\s*)$/i;

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




1;