import { prisma as db } from "@repo/db/client";

export const insuranceContactStorage = {
  async getInsuranceContactsByUser(userId: number) {
    return db.insuranceContact.findMany({
      where: { userId },
      orderBy: { name: "asc" },
    });
  },

  async createInsuranceContact(data: { userId: number; name: string; phoneNumber?: string }) {
    return db.insuranceContact.create({ data });
  },

  async updateInsuranceContact(id: number, data: { name?: string; phoneNumber?: string }) {
    return db.insuranceContact.update({ where: { id }, data });
  },

  async deleteInsuranceContact(userId: number, id: number) {
    const record = await db.insuranceContact.findFirst({ where: { id, userId } });
    if (!record) return false;
    await db.insuranceContact.delete({ where: { id } });
    return true;
  },
};
