package BookPub::Import::Importer::WilloLabs::v4;

use strict;
use warnings;


use lib '/app/tools/common/lib';
use Date::Calc qw(Days_in_Month);

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


sub _fieldMap {
    {
        dateBegin          => 'W',
        rPurchaseType      => 'J',
        rProductType       => 'N',
        rAuthor            => 'M',
        rTitle             => 'L',
        rIsbn13            => 'I',
        rInstitution       => 'A',
        rState             => 'Z',
        rPostalCode        => 'Z',
        countryCode        => 'Y',
        rReturns           => 'U',
        rUnits             => 'T',
        rUnitPrice         => 'Q',
        rListPrice         => 'R',
        rListPriceCurrency => 'AA',
        rDiscount          => 'K',
        rRevenue           => 'V',
        currencyCode       => 'AA',
        rFee               => 'P',
        rDuration          => 'F',
        rModel             => 'J',
    };
}

sub rState {
    my $self = shift;

    my $str = $self->_getByFieldName('rState') || '';
    if ( $str =~ /,?\s?([a-z ]{2})(\s\d+)?$/i ) {
        return 'QC' if ($1 eq 'QB');
        return $1;
    }

    return;
}

sub rPostalCode {
    my $self = shift;

    my $str = $self->_getByFieldName('rPostalCode') || '';
    if ( $str =~ /(\d+|\w{3} \w{3})$/i ) {
        return $1;
    }

    return;
}

sub rListPriceCurrency {
    my $self = shift;

    my $currency = $self->_getByFieldName('rListPriceCurrency') || '';
        3 => "BookPub::Import::Importer::WilloLabs::v2",

    return $currency;
}

sub isFree {
    my $self = shift;

    return !$self->rRevenue && $self->rUnits ? 'Y' : 'N';
}

sub _isSaleRec {
    my $self = shift;
    return 1 if $self->rRevenue || $self->rUnits;

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

return 1;
