-- CreateTable
CREATE TABLE "Opportunity" (
    "id" TEXT NOT NULL,
    "cwOpportunityId" INTEGER NOT NULL,
    "name" TEXT NOT NULL,
    "notes" TEXT,
    "typeName" TEXT,
    "typeCwId" INTEGER,
    "stageName" TEXT,
    "stageCwId" INTEGER,
    "statusName" TEXT,
    "statusCwId" INTEGER,
    "priorityName" TEXT,
    "priorityCwId" INTEGER,
    "ratingName" TEXT,
    "ratingCwId" INTEGER,
    "source" TEXT,
    "campaignName" TEXT,
    "campaignCwId" INTEGER,
    "primarySalesRepName" TEXT,
    "primarySalesRepIdentifier" TEXT,
    "primarySalesRepCwId" INTEGER,
    "secondarySalesRepName" TEXT,
    "secondarySalesRepIdentifier" TEXT,
    "secondarySalesRepCwId" INTEGER,
    "companyCwId" INTEGER,
    "companyName" TEXT,
    "contactCwId" INTEGER,
    "contactName" TEXT,
    "siteCwId" INTEGER,
    "siteName" TEXT,
    "customerPO" TEXT,
    "totalSalesTax" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "locationName" TEXT,
    "locationCwId" INTEGER,
    "departmentName" TEXT,
    "departmentCwId" INTEGER,
    "expectedCloseDate" TIMESTAMP(3),
    "pipelineChangeDate" TIMESTAMP(3),
    "dateBecameLead" TIMESTAMP(3),
    "closedDate" TIMESTAMP(3),
    "closedFlag" BOOLEAN NOT NULL DEFAULT false,
    "closedByName" TEXT,
    "closedByCwId" INTEGER,
    "companyId" TEXT,
    "cwLastUpdated" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Opportunity_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Opportunity_cwOpportunityId_key" ON "Opportunity"("cwOpportunityId");

-- AddForeignKey
ALTER TABLE "Opportunity" ADD CONSTRAINT "Opportunity_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE SET NULL ON UPDATE CASCADE;
