BEGIN;

CREATE TABLE IF NOT EXISTS parcel_user_status (
  user_id    text        NOT NULL,
  cad_num    text        NOT NULL,
  status     text        NOT NULL CHECK (status IN ('in_work', 'favorite', 'dismissed')),
  notes      text,
  updated_at timestamptz NOT NULL DEFAULT NOW(),
  PRIMARY KEY (user_id, cad_num)
);

CREATE INDEX IF NOT EXISTS parcel_user_status_cad_idx
    ON parcel_user_status (cad_num);

CREATE INDEX IF NOT EXISTS parcel_user_status_user_idx
    ON parcel_user_status (user_id, status);

COMMENT ON TABLE parcel_user_status
    IS '#307 SF-B1 user-marked parcels (in_work/favorite/dismissed) для карты.';

COMMIT;
