-- BizMatch Phase 2 — module 6b: the NDA form fields Dropbox Sign returns
--
-- A signed request carries every answer in response_data, so an import needs
-- no extraction model and no review step. These are the four answers that had
-- no column yet; the rest map onto existing buyer/contact/nda fields.

ALTER TABLE nda
  ADD COLUMN income_requirements text,
  ADD COLUMN accountant          text,
  ADD COLUMN attorney            text,
  ADD COLUMN bank                text,
  -- The untouched response_data array. Keeping it means a mapping mistake can
  -- be corrected later without going back to Dropbox for every round.
  ADD COLUMN raw_form_data       jsonb;

-- The backfill endpoint selects exactly this set.
CREATE INDEX nda_needs_form_data_idx ON nda (dropbox_sign_id)
  WHERE dropbox_sign_id IS NOT NULL AND status = 'SIGNED' AND raw_form_data IS NULL;
