-- CreateEnum
CREATE TYPE "AdminAction" AS ENUM ('LISTING_APPROVED', 'LISTING_REJECTED', 'LISTING_BULK_APPROVED', 'LISTING_BULK_REJECTED', 'USER_BANNED', 'USER_UNBANNED', 'USER_STATUS_UPDATED', 'KYC_APPROVED', 'KYC_REJECTED', 'SUBSCRIPTION_ADJUSTED');

-- CreateEnum
CREATE TYPE "AuditTargetType" AS ENUM ('USER', 'LISTING', 'SUBSCRIPTION');

-- CreateTable
CREATE TABLE "AdminAuditLog" (
    "id" TEXT NOT NULL,
    "action" "AdminAction" NOT NULL,
    "actorId" TEXT NOT NULL,
    "targetId" TEXT NOT NULL,
    "targetType" "AuditTargetType" NOT NULL,
    "metadata" JSONB,
    "ipAddress" TEXT,
    "userAgent" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "AdminAuditLog_actorId_idx" ON "AdminAuditLog"("actorId");

-- CreateIndex
CREATE INDEX "AdminAuditLog_targetId_targetType_idx" ON "AdminAuditLog"("targetId", "targetType");

-- CreateIndex
CREATE INDEX "AdminAuditLog_action_idx" ON "AdminAuditLog"("action");

-- CreateIndex
CREATE INDEX "AdminAuditLog_createdAt_idx" ON "AdminAuditLog"("createdAt");

-- CreateIndex
CREATE INDEX "AdminAuditLog_actorId_createdAt_idx" ON "AdminAuditLog"("actorId", "createdAt" DESC);

-- CreateIndex
CREATE INDEX "AdminAuditLog_action_createdAt_idx" ON "AdminAuditLog"("action", "createdAt" DESC);
