package BookPub::RDAS::Response::ProductPrice::Google;

use lib '/app/tools/bookpub/lib';
use base 'BookPub::RDAS::Response::ProductPrice';

sub serviceID { return BookPub::Tracker::Service::GOOGLE() }

sub _getMetadata {
    my $self = shift;

    my $isbn = $self->parser->ISBN();

    if ($isbn) {
        my ( $a, $b ) = split( /,\s?/, $isbn );

        $isbn10 = $a if ( $a && length($a) < 13 );
        $isbn13 = $a if ( $a && length($a) >= 13 );
        $isbn10 = $b if ( $b && length($b) < 13 );
        $isbn13 = $b if ( $b && length($b) >= 13 );
    }

    ( $title, $subtitle ) = split( /: /, $titleStr ) if ($titleStr);

    my $fields = {
        isbn13   => $isbn13,
        isbn10   => $isbn10,
        title    => $self->parser->Title(),
        subtitle => $self->parser->Subtitle(),
        format   => $self->parser->Format(),
        authors  => $self->parser->Author(),
        imprint  => $self->parser->Publisher(),
    };

    return $fields;
}

sub _getPriceData {
    my $self = shift;

    my $fields = { price => $self->parser->ProductPrice(), };

    return $fields;
}

sub _getCoverArtData {
    my $self = shift;

    my $fields = { cover_art_url => $self->parser->CoverURL(), };

    return $fields;
}

1;
