-- CreateEnum
CREATE TYPE "public"."ServiceType" AS ENUM ('HTTP', 'DATABASE', 'INSTANCE', 'SUBSCRIPTION');

-- CreateEnum
CREATE TYPE "public"."BillingCycle" AS ENUM ('MONTHLY', 'QUARTERLY', 'ANNUALLY', 'ONE_TIME', 'USAGE_BASED');

-- AlterTable
ALTER TABLE "public"."Service" ADD COLUMN     "billingCycle" "public"."BillingCycle",
ADD COLUMN     "enableCost" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN     "enableHealthCheck" BOOLEAN NOT NULL DEFAULT true,
ADD COLUMN     "identifier" TEXT,
ADD COLUMN     "ownerTeam" TEXT,
ADD COLUMN     "plan" TEXT,
ADD COLUMN     "provider" TEXT,
ADD COLUMN     "region" TEXT,
ADD COLUMN     "seats" INTEGER,
ADD COLUMN     "serviceType" "public"."ServiceType" NOT NULL DEFAULT 'HTTP',
ADD COLUMN     "vendor" TEXT;

-- CreateTable
CREATE TABLE "public"."CostSample" (
    "id" TEXT NOT NULL,
    "serviceId" TEXT NOT NULL,
    "date" TIMESTAMP(3) NOT NULL,
    "amountCents" INTEGER NOT NULL,
    "currency" TEXT NOT NULL DEFAULT 'THB',
    "originalCurrency" TEXT,
    "originalAmount" INTEGER,
    "source" TEXT NOT NULL,
    "metadata" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "Service_serviceType_idx" ON "public"."Service"("serviceType");

-- CreateIndex
CREATE INDEX "Service_ownerTeam_idx" ON "public"."Service"("ownerTeam");

-- CreateIndex
CREATE INDEX "Service_provider_region_idx" ON "public"."Service"("provider", "region");

-- CreateIndex
CREATE INDEX "Service_enableCost_idx" ON "public"."Service"("enableCost");

-- CreateIndex
CREATE UNIQUE INDEX "CostSample_serviceId_date_source_key" ON "public"."CostSample"("serviceId", "date", "source");

-- CreateIndex
CREATE INDEX "CostSample_date_idx" ON "public"."CostSample"("date");

-- CreateIndex
CREATE INDEX "CostSample_serviceId_date_idx" ON "public"."CostSample"("serviceId", "date");

-- CreateIndex
CREATE INDEX "CostSample_source_idx" ON "public"."CostSample"("source");

-- CreateIndex
CREATE INDEX "CostSample_date_source_idx" ON "public"."CostSample"("date", "source");

-- AddForeignKey
ALTER TABLE "public"."CostSample" ADD CONSTRAINT "CostSample_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "public"."Service"("id") ON DELETE CASCADE ON UPDATE CASCADE;