import { db } from "@/lib/db"
import type { PrismaClient } from "@prisma/client"

import type { BranchInput } from "./schema"

const prisma = db as PrismaClient as unknown as any

export async function listBranches() {
  return prisma.branch.findMany({ orderBy: { name: "asc" } })
}

export async function createBranch(input: BranchInput) {
  return prisma.branch.create({
    data: {
      name: input.name,
      location: input.location || undefined,
    },
  })
}

export async function deleteBranch(id: string) {
  return prisma.branch.delete({ where: { id } })
}
