package BookPub::Import::Importer::AthabascaUniversity::v1;

use strict;
use warnings;

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

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

sub _headerIdentifier { rProductType => 'CONTENT_TYPE' }

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }

sub productType   { shift->rProductType }
sub rProductType  { BookPub::DB::Item::Sale::kProductTypeEBook }
sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }

sub rServiceName {
    my $self = shift;

    my $name = $self->_getByFieldName('rServiceName') || '';
    return 'Capella' if $name =~ /^Capella University$/i;
    return 'Athabasca University' if $name =~ /^Athabasca University/i;

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

sub priceType {
    my $self = shift;

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

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

sub _isSaleRec {
    my $self = shift;

    return $self->dateBegin && $self->priceType ? 1 : 0;
}


1;
