package BookPub::Import::Importer::Kobo::Version2;

use strict;

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

sub _isAgency { return 'Y'; }

# NOTE:
# this version attempts to handle the varying layouts during what is hopefully only a
# "transitional" period for kobo starting in may 2010
#
# US taxable and non-taxable have the same layout (so far)
# canada and *usually* world drop the state & zip col
my %_fieldMap = (
    us => {
        date    => 0,
        country => 1,

        #state       => 2,
        #zip         => 3,
        units     => 4,
        isbn13    => 5,
        author    => 6,
        title     => 7,
        listPrice => 8,
        discount  => 9,
        revenue   => 10,
        currency  => 11,

        #taxRate     => 12,
        #taxAmt      => 13,
    },
    other => {
        date      => 0,
        country   => 1,
        units     => 2,
        isbn13    => 3,
        author    => 4,
        title     => 5,
        listPrice => 6,
        discount  => 7,
        revenue   => 8,
        currency  => 9,
    }
);

sub _getFieldMap {
    my ( $self, $dataRow, $sheetName ) = @_;

    # if the sheet name looks like 'US *' return USD for default currency
    # if the col for 'other' units is numeric only, it's the config without state/zip - else 'us'
    return ( $dataRow->[ $_fieldMap{other}{units} ] =~ m/^\d+$/ ? $_fieldMap{other} : $_fieldMap{us},
        $sheetName =~ m/\bus\b/i ? 'USD' : '', );
}

###
1;    # Play nicely.
###
