import { InvoiceType, TenantKind } from '@prisma/client';
import { prismaUnscoped } from './prisma';

/**
 * What an invoice is called in emails and payment links (27 Oct 2026). A
 * dormitory has no rent, mess or hostel: its invoices are a "Bill". A
 * hostel's rent and mess keep their names; anything else (one-off charges)
 * is a "Bill" too — before this it was wrongly called "Mess".
 */
export function invoiceKindWord(type: InvoiceType | string, dorm: boolean): string {
  if (dorm) return 'Bill';
  return type === InvoiceType.RENT ? 'Rent' : type === InvoiceType.MESS ? 'Mess' : 'Bill';
}

/** Whether a tenant is a dormitory, for wording. */
export async function isDormitoryTenant(tenantId: string): Promise<boolean> {
  const t = await prismaUnscoped.tenant.findUnique({ where: { id: tenantId }, select: { kind: true } });
  return t?.kind === TenantKind.DORMITORY;
}
