CREATE TABLE IF NOT EXISTS "pricing_promotions" (
  "id"            TEXT         NOT NULL,
  "code"          TEXT         NOT NULL,
  "name"          TEXT         NOT NULL,
  "description"   TEXT,
  "discountType"  TEXT         NOT NULL,
  "discountValue" INTEGER      NOT NULL,
  "plans"         TEXT[]       NOT NULL DEFAULT '{}',
  "periods"       TEXT[]       NOT NULL DEFAULT '{}',
  "maxUses"       INTEGER,
  "usedCount"     INTEGER      NOT NULL DEFAULT 0,
  "validFrom"     TIMESTAMP(3) NOT NULL,
  "validUntil"    TIMESTAMP(3),
  "isActive"      BOOLEAN      NOT NULL DEFAULT true,
  "createdAt"     TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "updatedAt"     TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "createdBy"     TEXT,
  CONSTRAINT "pricing_promotions_pkey" PRIMARY KEY ("id")
);

CREATE UNIQUE INDEX IF NOT EXISTS "pricing_promotions_code_key" ON "pricing_promotions"("code");
CREATE INDEX IF NOT EXISTS "pricing_promotions_isActive_idx"    ON "pricing_promotions"("isActive");
