import type { Prisma } from "@prisma/client";

export type OrderSP = { q?: string; status?: string; pay?: string; type?: string; page?: string };

export function whereFromParams(sp: OrderSP): Prisma.OrderWhereInput {
  const w: Prisma.OrderWhereInput = {};
  if (sp.q) w.OR = [{ number: { contains: sp.q } }, { customerName: { contains: sp.q } }, { phone: { contains: sp.q } }, { email: { contains: sp.q } }];
  if (sp.status) w.fulfillmentStatus = sp.status as never;
  if (sp.pay === "SUBMITTED") w.payments = { some: { status: "SUBMITTED" } };
  else if (sp.pay) w.paymentStatus = sp.pay as never;
  if (sp.type === "preorder") w.hasPreorder = true;
  if (sp.type === "ready") w.hasPreorder = false;
  return w;
}

export const payTone = { UNPAID: "warn", PENDING_VERIFICATION: "info", PARTIALLY_PAID: "warn", PAID: "good", PARTIALLY_REFUNDED: "warn", REFUNDED: "neutral" } as const;
