-- 085: Precise signature placement for e-signed documents.
--
-- Requirement: the client's drawn/typed signature must land exactly on the
-- signature line of the generated form, not in a generic "signed" sidecar.
--
-- When a document generator draws a signature line, it records the exact
-- PDF coordinates of each signature box in `signature_anchors`. At sign time
-- the stamper composites the signature PNG onto those coordinates and writes
-- the flattened, signed PDF to `signed_document_minio_key`.
--
-- signature_anchors shape (array, one entry per place a signature goes):
--   [
--     {
--       "field":  "signer",          -- which signature this box expects
--       "page":   0,                 -- 0-based page index
--       "x":      72.0,              -- lower-left x of the box, in PDF points
--       "y":      120.0,             -- lower-left y of the box, in PDF points
--       "w":      216.0,             -- box width  in points
--       "h":      40.0,              -- box height in points
--       "page_w": 612.0,            -- page width  the coordinates were authored against
--       "page_h": 792.0             -- page height the coordinates were authored against
--     }
--   ]

ALTER TABLE esign_records
    ADD COLUMN IF NOT EXISTS signature_anchors      JSONB,
    ADD COLUMN IF NOT EXISTS signed_document_minio_key TEXT;

COMMENT ON COLUMN esign_records.signature_anchors IS
    'Exact PDF coordinates of each signature box, recorded by the document generator so the stamper can place the signature on the signature line.';
COMMENT ON COLUMN esign_records.signed_document_minio_key IS
    'MinIO key of the flattened PDF with the signature stamped onto the signature line.';
