#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
#------------------------------------------------------------
package BookPub::DB::Item::ServiceSetting;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::Assert;

use Common::DB::Item;
use base 'Common::DB::Item';

use constant kTable => 'service_setting';
use constant kDB    => Common::DB::Item::kClientDB;

sub UpdateSetting {
    my $class = shift;
    my %args  = @_;

    assert( $args{serviceID} );

    my $sql = sprintf(
        "INSERT INTO "
          . kTable
          . " VALUES (%s, %s, %s, %s ) "
          . " ON DUPLICATE KEY UPDATE validate_price = %s, disable_agency_pricing = %s, disable_rrp_pricing = %s",
        $class->quote( $args{serviceID} ),
        $args{validatePrice} ? $class->quote( $args{validatePrice} ) : 'NULL',
        $args{disableAgency} ? $class->quote( $args{disableAgency} ) : 'NULL',
        $args{disableRRP}    ? $class->quote( $args{disableRRP} )    : 'NULL',

        $args{validatePrice} ? $class->quote( $args{validatePrice} ) : 'NULL',
        $args{disableAgency} ? $class->quote( $args{disableAgency} ) : 'NULL',
        $args{disableRRP}    ? $class->quote( $args{disableRRP} )    : 'NULL'
    );

    Log->error("SQL: $sql");

    my $dbo = Common::RSApp::GetClientDB();
    $dbo->DoCmd($sql) || die;
}

sub DeleteSetting {
    my $class = shift;
    my %args  = @_;

    assert( $args{serviceID} );

    my $sql = "DELETE FROM " . kTable . " WHERE service_id = " . $class->quote( $args{serviceID} );
    Log->error("SQL: $sql");

    my $dbo = Common::RSApp::GetClientDB();
    $dbo->DoCmd($sql) || die;
}

1;
