package BookPub::Import::Importer::VitalSource::Version18;

use strict;

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

sub _fieldMap {
    {
        dateBegin  => 'A1',
        rTitle     => 'B',
        rUnits     => 'C',
        rListPrice => 'D',
        rRevenue   => 'E',
        rIsbn13    => 'A',
    };
}

sub _headerIdentifier { ( rRevenue => 'Revenue' ) }

my %months = (
    jan => 1,
    feb => 2,
    mar => 3,
    apr => 4,
    may => 5,
    jun => 6,
    jul => 7,
    aug => 8,
    sep => 9,
    oct => 10,
    nov => 11,
    dec => 12,
);

sub _getDateBegin {
    my $self = shift;

    # February 2025 WGU VitalSource Count
    my $dateBegin = $self->_getByFieldName('dateBegin') || '';

    my ($month, $year) = $dateBegin =~ m/^(\w{3})\w{1,6}? (\d{4})/i;

    if ( $month && $year ) {
        return sprintf "%04d-%02d-%02d", $year, $months{ lc $month }, 1;
    }

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

sub _isSaleRec   {
    my $self = shift;

    my $title = $self->rIsbn13();
    return (!$title || ($title  =~ /^Grand Total$/) ? 0 : 1 );
}
1;
