package BookPub::Import::Importer::Follett::Version10;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use base 'BookPub::Import::Importer::Follett::Version9';

sub _fieldMap {
    {
        countryCode              => 'F',
        rPostalCode              => 'E',
        dateBegin                => 'A1',
        rIsbn13                  => 'A',
        rTitle                   => 'B',
        rAuthor                  => 'C',
        rUnits                   => 'H',
        rListPrice               => 'G',
        rDiscount                => 'I',
        rRevenue                 => 'L',
        rInstitution             => 'D',
        currencyCode             => 'M',
        rNativeListPrice         => 'G',
        rNativeListPriceCurrency => 'K',
    };
}

my %months = (
    january   => 1,
    february  => 2,
    march     => 3,
    april     => 4,
    may       => 5,
    june      => 6,
    july      => 7,
    august    => 8,
    september => 9,
    october   => 10,
    november  => 11,
    december  => 12,
);

sub dateBegin {
    my $self = shift;

    my $date = $self->_getByFieldName("dateBegin");

    if ( $date =~ /\b(\w+)\b (\d{4})$/ ) {
        my ($year, $month)  = ($2, lc($1));
        return sprintf( "%04d-%02d-%02d", $year, $months{$month}, 1 );
    }

    $self->fail("Unexpected date format");
}

1;
