CREATE TABLE public.conflux_webhook_events (
  id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
  notify_id TEXT NOT NULL,
  notify_type TEXT NOT NULL,
  flow_order_no TEXT,
  mch_order_no TEXT,
  order_id TEXT,
  trade_status TEXT,
  amount BIGINT,
  currency TEXT,
  way_code TEXT,
  raw_payload JSONB,
  received_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
  created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
  CONSTRAINT conflux_webhook_events_notify_unique UNIQUE (notify_id)
);

GRANT ALL ON public.conflux_webhook_events TO service_role;

ALTER TABLE public.conflux_webhook_events ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Service role manages conflux webhook events"
  ON public.conflux_webhook_events FOR ALL
  TO service_role
  USING (true) WITH CHECK (true);