import { count, eq } from 'drizzle-orm';
import type { DrizzleClient } from '@/server/db/client';
import { dealSkus } from '@/server/db/schema';

export async function validateDealHasSkus(tx: DrizzleClient, dealId: string): Promise<void> {
  const rows = await tx
    .select({ n: count() })
    .from(dealSkus)
    .where(eq(dealSkus.dealId, dealId));
  if (!rows[0] || rows[0].n === 0) {
    throw new Error(`DEAL_HAS_NO_SKU: ${dealId}`);
  }
}
