-- Migration: 20260423000000_add_vnbds_compliance_fields
-- Luật Kinh doanh BĐS 2023, Điều 6-7 + Nghị định 96/2024, Điều 62

CREATE TYPE "BrokerCertStatus" AS ENUM (
  'UNVERIFIED', 'PENDING_REVIEW', 'VERIFIED', 'EXPIRED', 'REVOKED'
);

ALTER TABLE "Property"
  ADD COLUMN "certificateNumber"   TEXT,
  ADD COLUMN "certificateIssuedAt" TIMESTAMP(3),
  ADD COLUMN "certificateIssuedBy" TEXT,
  ADD COLUMN "hasMortgage"         BOOLEAN NOT NULL DEFAULT FALSE,
  ADD COLUMN "hasDispute"          BOOLEAN NOT NULL DEFAULT FALSE,
  ADD COLUMN "legalEncumbrances"   TEXT;

ALTER TABLE "Agent"
  ADD COLUMN "brokerCertNumber"   TEXT,
  ADD COLUMN "brokerCertIssuedAt" TIMESTAMP(3),
  ADD COLUMN "brokerCertExpiryAt" TIMESTAMP(3),
  ADD COLUMN "brokerCertStatus"   "BrokerCertStatus" NOT NULL DEFAULT 'UNVERIFIED',
  ADD COLUMN "brokerCertDocUrl"   TEXT;

CREATE INDEX "Agent_brokerCertStatus_idx" ON "Agent"("brokerCertStatus");
CREATE INDEX "Agent_brokerCertExpiryAt_idx" ON "Agent"("brokerCertExpiryAt");
