-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Product" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "metalType" TEXT NOT NULL,
    "weight" TEXT NOT NULL,
    "purity" TEXT NOT NULL,
    "karat" TEXT,
    "productType" TEXT NOT NULL,
    "itemKind" TEXT NOT NULL DEFAULT 'PHYSICAL_BULLION',
    "isPublicProduct" BOOLEAN NOT NULL DEFAULT true,
    "isServiceItem" BOOLEAN NOT NULL DEFAULT false,
    "mintBrand" TEXT NOT NULL,
    "brandMint" TEXT NOT NULL DEFAULT 'Generic Bullion',
    "supplierId" TEXT NOT NULL,
    "categoryId" TEXT,
    "pricingMode" TEXT NOT NULL DEFAULT 'DIRECT_MANUAL',
    "manualPrice" DECIMAL NOT NULL DEFAULT 0,
    "supplierPrice" DECIMAL NOT NULL,
    "markupPercent" DECIMAL NOT NULL DEFAULT 10,
    "customerPrice" DECIMAL NOT NULL DEFAULT 0,
    "totalSalePrice" DECIMAL NOT NULL,
    "shortDescription" TEXT NOT NULL DEFAULT '',
    "description" TEXT NOT NULL,
    "imageUrls" TEXT NOT NULL DEFAULT '[]',
    "images" TEXT NOT NULL,
    "inventoryStatus" TEXT NOT NULL DEFAULT 'IN_STOCK',
    "stockStatus" TEXT NOT NULL DEFAULT 'IN_STOCK',
    "stockQuantity" INTEGER NOT NULL DEFAULT 0,
    "premiumPercent" DECIMAL NOT NULL DEFAULT 0,
    "spreadPercent" DECIMAL NOT NULL DEFAULT 0,
    "liquidityScore" INTEGER NOT NULL DEFAULT 3,
    "shippingSpeedScore" INTEGER NOT NULL DEFAULT 3,
    "recommendationNotes" TEXT,
    "isIraEligible" BOOLEAN NOT NULL DEFAULT false,
    "isFeatured" BOOLEAN NOT NULL DEFAULT false,
    "priceLastUpdatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "lastPriceUpdatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "seoTitle" TEXT,
    "seoDescription" TEXT,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "Product_supplierId_fkey" FOREIGN KEY ("supplierId") REFERENCES "Supplier" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "Product_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_Product" ("brandMint", "categoryId", "createdAt", "customerPrice", "description", "id", "imageUrls", "images", "inventoryStatus", "isFeatured", "isIraEligible", "isPublicProduct", "isServiceItem", "itemKind", "karat", "lastPriceUpdatedAt", "manualPrice", "markupPercent", "metalType", "mintBrand", "name", "priceLastUpdatedAt", "pricingMode", "productType", "purity", "seoDescription", "seoTitle", "shortDescription", "slug", "stockQuantity", "stockStatus", "supplierId", "supplierPrice", "totalSalePrice", "updatedAt", "weight") SELECT "brandMint", "categoryId", "createdAt", "customerPrice", "description", "id", "imageUrls", "images", "inventoryStatus", "isFeatured", "isIraEligible", "isPublicProduct", "isServiceItem", "itemKind", "karat", "lastPriceUpdatedAt", "manualPrice", "markupPercent", "metalType", "mintBrand", "name", "priceLastUpdatedAt", "pricingMode", "productType", "purity", "seoDescription", "seoTitle", "shortDescription", "slug", "stockQuantity", "stockStatus", "supplierId", "supplierPrice", "totalSalePrice", "updatedAt", "weight" FROM "Product";
DROP TABLE "Product";
ALTER TABLE "new_Product" RENAME TO "Product";
CREATE UNIQUE INDEX "Product_slug_key" ON "Product"("slug");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
