package BookPub::Import::Importer::Bibliu::v1;

use strict;
use warnings;

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

sub _fieldMap {
    {
        dateBegin              => 'Z',
        dateEnd                => 'Z',
        rFormat                => 'F',
        rTitle                 => 'C',
        rIsbn13                => 'E',
        rInstitution           => 'U',
        countryCode            => 'W',
        rReturns               => 'H',
        rSales                 => 'G',
        rUnits                 => 'I',
        rListPrice             => 'K',
        rListPriceCurrency     => 'M',
        rPurchasePrice         => 'O',
        rPurchasePriceCurrency => 'M',
        rDiscount              => 'N',
        rRevenue               => 'Q',
        currencyCode           => 'R',
        rFee                   => 'P',
        rDuration              => 'S',
        rTransactionCategory   => 'X',
    };
}

sub _headerIdentifier { rTitle => 'Title' }


sub rServiceName  { 'BibliU' }
sub _useIsSaleRec { 1 }
sub purchaseType  { BookPub::DB::Item::Sale::kPurchaseTypeSubscriptionDL }
sub productType   { BookPub::DB::Item::Sale::kProductTypeEBook }
sub rPriceType    { 'rrp' }

sub _getDateBegin {
    my $self = shift;

    my $dateBegin = $self->_getByFieldName('dateBegin') || '';
    if ( $dateBegin =~ /^\d{5}$/ and $dateBegin > 38716 ) {
        $dateBegin = Spreadsheet::ParseExcel::Utility::ExcelFmt( "yyyy-mm-dd", $dateBegin );
        return $dateBegin;
    }

    return $dateBegin;
}

sub _getDateEnd {
    my $self = shift;

    my $dateEnd = $self->_getByFieldName('dateEnd') || '';
    if ( $dateEnd =~ /^\d{5}$/ and $dateEnd > 38716 ) {
        $dateEnd = Spreadsheet::ParseExcel::Utility::ExcelFmt( "yyyy-mm-dd", $dateEnd );
        return $dateEnd;
    }

    return $dateEnd;
}

1;