-- CreateEnum
CREATE TYPE "SiteStatus" AS ENUM ('active', 'inactive', 'suspended');

-- AlterTable: Add site_limit to subscriptions
ALTER TABLE "subscriptions" ADD COLUMN "site_limit" INTEGER;

-- CreateTable: wordpress_sites with site licensing support
CREATE TABLE "wordpress_sites" (
    "id" UUID NOT NULL,
    "user_id" UUID NOT NULL,
    "api_key_id" UUID NOT NULL,
    "site_uuid" TEXT NOT NULL,
    "site_url" TEXT NOT NULL,
    "site_name" TEXT NOT NULL,
    "wp_version" TEXT NOT NULL,
    "plugin_version" TEXT NOT NULL,
    "is_staging" BOOLEAN NOT NULL DEFAULT false,
    "status" "SiteStatus" NOT NULL DEFAULT 'active',
    "activated_at" TIMESTAMP(3),
    "last_validated_at" TIMESTAMP(3) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "php_version" TEXT,
    "installed_plugins" JSONB,
    "active_theme" TEXT,
    "locale" TEXT DEFAULT 'en_US',
    "timezone" TEXT,

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

-- CreateIndex
CREATE UNIQUE INDEX "wordpress_sites_site_uuid_key" ON "wordpress_sites"("site_uuid");

-- CreateIndex
CREATE INDEX "wordpress_sites_user_id_idx" ON "wordpress_sites"("user_id");

-- CreateIndex
CREATE INDEX "wordpress_sites_api_key_id_idx" ON "wordpress_sites"("api_key_id");

-- CreateIndex
CREATE INDEX "wordpress_sites_site_uuid_idx" ON "wordpress_sites"("site_uuid");

-- CreateIndex
CREATE INDEX "wordpress_sites_site_url_idx" ON "wordpress_sites"("site_url");

-- CreateIndex
CREATE INDEX "wordpress_sites_status_idx" ON "wordpress_sites"("status");

-- CreateIndex
CREATE INDEX "wordpress_sites_is_staging_idx" ON "wordpress_sites"("is_staging");

-- CreateIndex
CREATE INDEX "wordpress_sites_last_validated_at_idx" ON "wordpress_sites"("last_validated_at");

-- AddForeignKey
ALTER TABLE "wordpress_sites" ADD CONSTRAINT "wordpress_sites_user_id_fkey"
  FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "wordpress_sites" ADD CONSTRAINT "wordpress_sites_api_key_id_fkey"
  FOREIGN KEY ("api_key_id") REFERENCES "api_keys"("id") ON DELETE CASCADE ON UPDATE CASCADE;
