--
-- This file is part of TALER
-- Copyright (C) 2026 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
-- Foundation; either version 3, or (at your option) any later version.
--
-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-- A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with
-- TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>

-- @file pg_merchant_kyc_trigger.sql
-- @brief Fix trigger logic
-- @author Christian Grothoff


CREATE OR REPLACE FUNCTION merchant_kyc_update_trigger()
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
  IF (OLD.kyc_ok
     ,OLD.last_rule_gen
     ,OLD.aml_review
     ,OLD.jaccount_limits)
  IS DISTINCT FROM
     (NEW.kyc_ok
     ,NEW.last_rule_gen
     ,NEW.aml_review
     ,NEW.jaccount_limits)
  THEN
    CALL merchant_send_kyc_notification(NEW.account_serial,
                                        NEW.exchange_url);
  END IF;
  RETURN NEW;
END $$;
