-- 015_recipient_key.sql
-- Adds recipient key columns to customers table to support decrypt.html for recipients.
-- Mirrors the sender key flow (sender_key_hmac, sender_key_issued_at, etc.)

ALTER TABLE customers
  ADD COLUMN IF NOT EXISTS recipient_key_hmac         TEXT,
  ADD COLUMN IF NOT EXISTS recipient_key_issued_at    TEXT,
  ADD COLUMN IF NOT EXISTS recipient_key_expires_at   TIMESTAMP WITH TIME ZONE,
  ADD COLUMN IF NOT EXISTS recipient_key_purchased_at TIMESTAMP WITH TIME ZONE,
  ADD COLUMN IF NOT EXISTS recipient_key_viewed       BOOLEAN NOT NULL DEFAULT FALSE,
  ADD COLUMN IF NOT EXISTS recipient_key_used         BOOLEAN NOT NULL DEFAULT FALSE;

COMMENT ON COLUMN customers.recipient_key_hmac         IS 'HMAC for recipient purchase key verification';
COMMENT ON COLUMN customers.recipient_key_issued_at    IS 'Timestamp when recipient key was issued (for HMAC)';
COMMENT ON COLUMN customers.recipient_key_expires_at   IS 'When recipient decryption window expires';
COMMENT ON COLUMN customers.recipient_key_purchased_at IS 'When recipient purchased their key';
COMMENT ON COLUMN customers.recipient_key_viewed       IS 'Whether recipient has viewed their key page';
COMMENT ON COLUMN customers.recipient_key_used         IS 'Whether recipient has used their key to decrypt';
