/**
 * Business hours query helpers.
 */

import { eq } from 'drizzle-orm';
import type { DrizzleClient } from '../client.js';
import { businessHours } from '../schema.js';

export type CreateBusinessHoursInput = typeof businessHours.$inferInsert;

export async function createBusinessHours(
  db: DrizzleClient,
  values: CreateBusinessHoursInput,
): Promise<void> {
  await db.insert(businessHours).values(values);
}

/**
 * Returns the business hours row for a vendor, or undefined if none exists.
 * One vendor = one business hours row (LIMIT 1).
 */
export async function getHoursForVendor(
  db: DrizzleClient,
  vendorId: string,
): Promise<typeof businessHours.$inferSelect | undefined> {
  const [row] = await db
    .select()
    .from(businessHours)
    .where(eq(businessHours.vendorId, vendorId))
    .limit(1);
  return row;
}
