-- Historique des changements de statut KYC
-- Aucun chemin de fichier n'est stocké ici ; les documents restent dans le bucket privé.

CREATE TABLE IF NOT EXISTS prestataire_kyc_history (
  id                 UUID        PRIMARY KEY DEFAULT gen_random_uuid(),
  prestataire_id     UUID        NOT NULL REFERENCES prestataires(id) ON DELETE CASCADE,
  verification_type  TEXT        NOT NULL CHECK (verification_type IN ('identity', 'siret', 'casier', 'lien_parente')),
  action             TEXT        NOT NULL CHECK (action IN ('submitted', 'validated', 'rejected', 'deleted', 'reset', 'updated')),
  old_status         TEXT,
  new_status         TEXT        NOT NULL,
  admin_id           UUID        REFERENCES utilisateurs(id) ON DELETE SET NULL,
  created_at         TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS prestataire_kyc_history_prestataire_idx ON prestataire_kyc_history (prestataire_id, created_at DESC);
