package BookPub::Import::Importer::Yuzu::Version5;

use strict;

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

use Date::Calc qw( Add_Delta_YM );

sub _fieldMap {
    my $self = shift;

    my %fieldMap = (
        5 => {
            rPurchaseType    => 'H',
            serviceProductID => 'B',
            currencyCode     => 'L',
            rPostalCode      => 'O',
            dateBegin        => 'M',
            rFormat          => 'F',
            rIsbn13          => 'C',
            rTitle           => 'E',
            rAuthor          => 'D',
            rUnits           => 'I',
            rSales           => 'P',
            rReturns         => 'P',
            rListPrice       => 'J',
            rRevenue         => 'K',
        },
    );

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

sub _unverifiedFieldMap {
    my $self = shift;

    my %fieldMap = (
        5 => {
            subtotalCheck => 'A',
        },
    );

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

sub priceType                  { 'agency' }
sub countryCode                { 'US' }
sub _useIsSaleRec              { 1 }
sub _autoParseTitleAndSubtitle { 1 }

sub rFormat { shift->_getByFieldName('rFormat') }

sub _getDateBegin {
    my $self      = shift;
    my $dateBegin = $self->_getByFieldName('dateBegin');

    return substr( $dateBegin, 0, 10 );
}

sub rSales {
    my $self = shift;

    my $sales = $self->_getByFieldName('rSales');
    if ( $sales =~ /sale/i ) {
        return 1;
    }
}

sub rReturns {
    my $self = shift;

    my $returns = $self->_getByFieldName('rReturns');
    if ( $returns =~ /return/i || $returns =~ /void/i ) {
        return 1;
    }
}

sub rListPrice { shift->_getByFieldName('rListPrice') }

1;
