-- Operational settings the editor changes from the admin portal.
--
-- Deliberately NOT the CMS, which is where this project otherwise puts
-- editor-changeable values (see .env.example on the UPI payee). The dividing
-- line: cms_content holds text rendered to readers; app_settings holds values
-- the system branches on.
--
-- Four concrete reasons the CMS is wrong for these:
--   * UpdateCmsContentRequest requires both a Hindi and an English value. A
--     boolean has no bilingual pair; we would be storing 'true'/'true'.
--   * cms_content.value is untyped TEXT. The whole point here is a typed
--     accessor with bounds — that is what stops Rs.7 being charged for Rs.700.
--   * The Page Content screen renders every row as two free-text boxes with no
--     numeric validation, directly beside the UPI payee address.
--   * GET /public/cms/{section} is permitAll. This table lets each key decide
--     for itself whether it is public.
CREATE TABLE app_settings (
    key         VARCHAR(64) PRIMARY KEY,
    value       TEXT        NOT NULL,
    updated_by  UUID        REFERENCES users(id) ON DELETE SET NULL,
    updated_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

COMMENT ON TABLE app_settings IS
    'Editor-controlled operational parameters. Values are strings; SettingsService owns parsing and bounds.';

-- Seeded true so behaviour is unchanged by this migration: the fee was already
-- being charged via REVIEW_FEE_PAISE, and a migration should not silently stop
-- a journal collecting money.
INSERT INTO app_settings (key, value) VALUES
    ('payments.enabled', 'true')
ON CONFLICT (key) DO NOTHING;

-- Rs.700.00. Mirrors the REVIEW_FEE_PAISE default so nothing changes price on
-- deploy. Stored in paise because that is what the payments table stores and
-- what the UPI amount is derived from; the admin form works in rupees and
-- converts, so nobody types paise by hand.
--
-- GST stays in server configuration. It is a statutory rate, not an editorial
-- decision, and a mistyped rate is a compliance problem rather than a pricing one.
INSERT INTO app_settings (key, value) VALUES
    ('payments.review_fee_paise', '70000')
ON CONFLICT (key) DO NOTHING;
