--
-- This file is part of TALER
-- Copyright (C) 2014--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/>
--

SET search_path TO auditor;
CREATE TABLE IF NOT EXISTS auditor_aml_staff
(
    row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
    decider_pub BYTEA NOT NULL CHECK (LENGTH(decider_pub)=32),
    decider_name TEXT NOT NULL,
    is_active BOOLEAN NOT NULL,
    read_only BOOLEAN NOT NULL,
    master_sig_valid BOOLEAN NOT NULL,
    last_change INT8 NOT NULL,
    UNIQUE (decider_pub, last_change)
);
COMMENT ON TABLE auditor_aml_staff
    IS 'Status changes of the exchange''s AML staff, as observed by the auditor. The exchange''s own aml_staff is append-only and holds the same history, but only as a promise its code makes; this is the auditor''s independent record of who was allowed to decide when, and of what it had already seen when.';
COMMENT ON COLUMN auditor_aml_staff.decider_pub
  IS 'Public key of the AML staff member';
COMMENT ON COLUMN auditor_aml_staff.is_active
  IS 'true if the staff member was allowed to act from last_change onwards';
COMMENT ON COLUMN auditor_aml_staff.read_only
  IS 'true if the staff member had read-only access from last_change onwards, and thus could not legitimately sign decisions';
COMMENT ON COLUMN auditor_aml_staff.master_sig_valid
  IS 'true if the exchange''s offline master key really did sign this status. A status that fails this check confers no authority, but is still recorded so that the finding is raised once instead of on every round.';
COMMENT ON COLUMN auditor_aml_staff.last_change
  IS 'Time from which this status was in force, as claimed by the exchange. The status holds until the next change for the same decider_pub.';
