-- AlterEnum: Add DISPUTED status for chargeback tracking
ALTER TYPE "OrderStatus" ADD VALUE 'DISPUTED';

-- DropForeignKey: Make paymentId optional on audit log
ALTER TABLE "payment_audit_log" DROP CONSTRAINT "payment_audit_log_payment_id_fkey";

-- AlterTable: Add orderId column, make paymentId nullable
ALTER TABLE "payment_audit_log" ADD COLUMN     "order_id" TEXT,
ALTER COLUMN "payment_id" DROP NOT NULL;

-- CreateIndex
CREATE INDEX "idx_payment_audit_log_order" ON "payment_audit_log"("order_id");

-- AddForeignKey (nullable)
ALTER TABLE "payment_audit_log" ADD CONSTRAINT "payment_audit_log_payment_id_fkey" FOREIGN KEY ("payment_id") REFERENCES "payments"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "payment_audit_log" ADD CONSTRAINT "payment_audit_log_order_id_fkey" FOREIGN KEY ("order_id") REFERENCES "orders"("id") ON DELETE SET NULL ON UPDATE CASCADE;
