-- +goose Up
CREATE TABLE IF NOT EXISTS notification_delivery_logs (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  tenant_id uuid NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
  reminder_job_id uuid REFERENCES reminder_jobs(id) ON DELETE SET NULL,
  channel text NOT NULL,
  provider text NOT NULL,
  recipient text NOT NULL,
  delivery_status text NOT NULL,
  external_id text,
  error_message text,
  created_at timestamptz NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_notification_delivery_logs_tenant_time
  ON notification_delivery_logs (tenant_id, created_at DESC);

-- +goose Down
DROP INDEX IF EXISTS idx_notification_delivery_logs_tenant_time;
DROP TABLE IF EXISTS notification_delivery_logs;
