package BookPub::Import::Importer::Bookish::Version1;

use strict;

use Common::Assert;
use Data::Dumper;

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

sub _fieldMap {
    {
        currencyCode => 'C',
        countryCode  => 'B',
        dateBegin    => 'A',
        rIsbn13      => 'D',
        rTitle       => 'E',
        rAuthor      => 'F',
        rListPrice   => 'H',
        rDiscount    => 'K',
        rRevenue     => 'L',
    };
}

sub _headerIdentifier { ( rTitle => 'Title' ) }
sub purchaseType      { BookPub::DB::Item::Sale::kPurchaseTypeDownload }
sub priceType         { 'rrp' }
sub productType       { BookPub::DB::Item::Sale::kProductTypeEBook }
sub rUnits            { 1 }

sub rDiscount {
    my $self     = shift;
    my $discount = $self->SUPER::rDiscount();

    return 1 - $discount;
}

sub rListPrice {
    my $self = shift;

    my $price = $self->SUPER::rListPrice();
    $price =~ s/\$//g;

    return $price;
}

sub rRevenue {
    my $self = shift;

    my $revenue = $self->SUPER::rRevenue();
    $revenue =~ s/,|\$//g;

    return $revenue;
}

sub rTitle {
    my $self = shift;

    my $title = $self->SUPER::rTitle();
    $title =~ s/ ~autofilled~$//;

    if ( $title =~ /(.+):.+/ ) {
        $title = $1;
    }

    return $title;
}

sub rSubtitle {
    my $self = shift;

    my $title = $self->SUPER::rTitle();
    my $subtitle;

    if ( $title =~ /.+: (.+)/ ) {
        $subtitle = $1;
    }

    return $subtitle;
}

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