package Common::DB::Item::TableChangeLog;

use strict;
use warnings;

use lib '/app/tools/common/lib';
use Common::DB::ItemCollection;
use Common::DB::Item;

# !!! Important safety tip !!!
# Don't _ever_ change this class to inherit from Common::DB::LogWhenChangedItem,
# or terrible things will happen (probably).
#
use base 'Common::DB::Item';

use constant kTable => 'table_change_log';
use constant kDB    => Common::DB::Item::kCommonDB();

use constant kActionUpdate => 'UPDATE';
use constant kActionInsert => 'INSERT';
use constant kActionDelete => 'DELETE';

use constant kStatusNew       => 'NEW ';
use constant kStatusBad       => 'BAD ';
use constant kStatusSkipped   => 'SKIP';
use constant kStatusProcessed => 'DONE';
use constant kStatusNoDelete  => 'NODL';
use constant kStatusDuplicate => 'DUPE';

sub GetAllNew {
    my ($class) = @_;

    return $class->SUPER::GetAll( "SELECT * FROM " . kTable . " WHERE status='" . kStatusNew . "'" );
}

sub GetAllUnNotified {
    my ( $class, $client_id ) = @_;

    my $dbo = Common::RSApp::GetCommonDB();
    my $sql =
      "SELECT * FROM " . kTable . " WHERE client_id = " . $dbo->DBQuote($client_id) . " AND " . "( notified IS NULL OR not notified )";

    Common::Log::Debug("QUERY: $sql");
    return $class->SUPER::GetAll($sql);
}

1;
