package BookPub::Import::Importer::Readwell::Version4;

use lib '/app/tools/bookpub/lib';

use strict;
use BookPub::DB::Item::PriceType;

use base 'BookPub::Import::Importer::Readwell';

sub _headerIdentifier { ( rIsbn13 => 'main_product_id' ) }

sub priceType {
    my $self     = shift;
    my $type     = $self->_getByFieldName('priceType');
    my $clientID = Common::RSApp::GetClientID;

    if ( $clientID == 318 ) {    #Macmillan US always agency, despite file data, FB11987
        return 'agency';
    } else {
        my $typeID =
            $type == BookPub::DB::Item::PriceType::kPriceTypeRRP           ? 'rrp'
          : $type == BookPub::DB::Item::PriceType::kPriceTypeRRPPlusTax    ? 'rrpplustax'
          : $type == BookPub::DB::Item::PriceType::kPriceTypeAgency        ? 'agency'
          : $type == BookPub::DB::Item::PriceType::kPriceTypeAgencyPlusTax ? 'agencyplustax'
          :                                                                  undef;

        $self->fail("Unknown price type '$type'") unless ($typeID);
        return $typeID;
    }
}

# don't want to use the sub from the parent class
sub rUnitPrice {
    my $self  = shift;
    my $price = $self->_getByFieldName('rUnitPrice');

    return $price;
}

# don't want to use the sub from the parent class
sub rRevenue {
    my $self    = shift;
    my $revenue = $self->_getByFieldName('rRevenue');

    return $revenue;
}

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