package BookPub::Import::Importer::UnizinPOD;

use strict;
use Date::Calc qw(Days_in_Month);

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

sub _headerIdentifier { ( rIsbn13 => 'Textbook ISBN' ) }

# map version num to the field order
sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        1 => {
            dateBegin    => 'A',
            rTitle       => 'B',
            rIsbn13      => 'F',
            rInstitution => 'H',
            rListPrice   => 'C',
            rRevenue     => 'E',
        },
    );

    return $fieldMap{ $self->_version() };
}

sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }
sub priceType                  { 'rrp' }
sub purchaseType               { BookPub::DB::Item::Sale::kPurchaseTypePrintOnDemand }
sub productType                { BookPub::DB::Item::Sale::kProductTypePhysicalBook }
sub countryCode                { 'US' }
sub currencyCode               { 'USD' }
sub rListPriceCurrency         { 'USD' }

sub rUnits {
    my $self = shift;

    my $revenue = $self->revenue();

    if ( $revenue < 0 ) {
        return -1;
    } else {
        return 1;
    }
}

sub rTransactionCategory {
    my $self = shift;

    my $filename = $self->filename;

    if ( $filename =~ /POD/ ) {
        return "POD";
    } else {
        $self->fail("POD not found in file name");
    }
}

sub _isSaleRec {
    my $self = shift;

    my $isbn13 = $self->_getByFieldName('rIsbn13');

    # We're going to skip the subtotal line
    if ( $isbn13 =~ /Amount to invoice Unizin/i ) {
        return 0;
    }

    return $self->SUPER::_isSaleRec();
}

1;
