-- New enum values for manually reconciled payments.
--
-- Separate from V24 for the same reason V2 is separate from V3: Postgres will
-- not let a value added by ALTER TYPE be used in the same transaction, and
-- Flyway wraps each migration in one. V24 both uses and seeds these.

-- The paper waits here until someone confirms the money arrived. Chosen over
-- letting unpaid papers into the review queue: reviewer time is the scarce
-- resource on this journal, and chasing a fee after the review is done has no
-- leverage at all.
ALTER TYPE paper_status ADD VALUE IF NOT EXISTS 'PAYMENT_PENDING';

-- The author has given a transaction reference and is waiting on a human to
-- match it against the bank statement. Distinct from PENDING (nothing declared
-- yet) because it is the state that needs someone's attention, and distinct
-- from SUCCESS because a claim is not a payment — only the statement proves it.
ALTER TYPE payment_status ADD VALUE IF NOT EXISTS 'AWAITING_CONFIRMATION';

-- An admin looked and could not find the money. Not FAILED, which means the
-- gateway declined it; this is a human judgement and the author can correct
-- the reference and try again.
ALTER TYPE payment_status ADD VALUE IF NOT EXISTS 'REJECTED';

-- How the money moved. UPI collections are reconciled by hand from a bank
-- statement; RAZORPAY would be confirmed by a signed callback. Both can exist
-- at once, which is the point of recording it.
DO $$ BEGIN
    CREATE TYPE payment_method AS ENUM ('MANUAL_UPI', 'RAZORPAY');
EXCEPTION WHEN duplicate_object THEN NULL;
END $$;

-- CMS section holding the UPI details shown to authors, so the editor can
-- change the payee without a deployment.
ALTER TYPE content_section ADD VALUE IF NOT EXISTS 'PAYMENT';
