import type { DB } from "../generated/kysely-tailordb";
import { ok, type ReadonlyDB } from "@tailor-platform/erp-kit/module";

export interface GetDefaultPartnerBankAccountInput {
  partnerId: string;
}

export async function run(db: ReadonlyDB<DB>, input: GetDefaultPartnerBankAccountInput) {
  const partnerBankAccount = await db
    .selectFrom("PartnerBankAccount")
    .selectAll()
    .where("partnerId", "=", input.partnerId)
    .where("isDefault", "=", true)
    .executeTakeFirst();

  return ok({ partnerBankAccount: partnerBankAccount ?? null });
}
