package BookPub::Import::Importer::Google::Version12;

use strict;

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

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

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

sub _fieldMap {
    {
        dateBegin          => 'B',
        rUnits             => 'E',
        rIsbn13            => 'G',
        rImprint           => 'H',
        rTitle             => 'I',
        rAuthor            => 'J',
        rListPriceCurrency => 'K',
        rListPrice         => 'L',
        countryCode        => 'M',
        rState             => 'N',
        rPostalCode        => 'O',
        rDiscount          => 'R',
        currencyCode       => 'U',
        conversionRate     => 'W',
    };
}

sub _unverifiedFieldMap {
    { publisherRevenue => 'S', };
}

sub priceType { 'agency' }

sub revenue {
    my $self = shift;

    my $convRate = $self->_getByFieldName('conversionRate');
    my $rRev     = $self->_getByFieldName('publisherRevenue');

    if ( !$convRate || $convRate == '' ) {
        $convRate = 1;
    }

    return $convRate * $rRev;
}

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

    return 1 - $discount;
}

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;
