package BookPub::Import::Importer::INscribeDigital::Version1;

use strict;

use Common::Country;

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

sub _headerIdentifier { ( rTitle => 'TITLE' ) }

# We have to do some odd things with the field map here because this importer has
# different column definitions of seperate tabs.  The map is defined by tab name below.
# The summary tab is ignored (returns and empty field set).
sub _fieldMap {
    my $self = shift;

    my $map = {
        'details' => {
            countryCode => 'H',
            dateBegin   => 'A',
            dateEnd     => 'C',
            isbn        => 'G',
            rTitle      => 'F',
            rAuthor     => 'E',
            rUnits      => 'I',
            rListPrice  => 'L',
            rRevenue    => 'K',
        },
    };

    # ignore all sheets except 'details'
    my $sheet = lc( $self->sheetname ) || return {};
    $sheet =~ /details/ ? return $map->{$sheet} : return {};
}

sub priceType    { 'rrp' }
sub purchaseType { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub productType  { BookPub::DB::Item::Sale::kProductTypeEBook }
sub currencyCode { 'USD' }

sub countryCode {
    my $self = shift;
    my $code = $self->SUPER::countryCode();

    my $countryObj = Common::Country->Get($code) || $self->fail("Unknown country code '$code'");

    return $countryObj->alpha2();
}

#sub countryCode {
#    my $self = shift;
#	my $country = $self->_getByFieldName( 'countryCode' );
#
#    my $code = $Common::Consts::COUNTRY_CODE{lc $country};
#    unless ($code) { $self->fail("Unknown country: $country") };
#    return $code;
#}

#sub _dateFormat { [ 'iso', 'excel', 'text', 'eur' ] }

1;
