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

/**
 * Retrieves the currency designated as the base currency.
 * Returns null if no base currency has been set.
 */
export async function run(db: ReadonlyDB<DB>) {
  const currency = await db
    .selectFrom("Currency")
    .selectAll()
    .where("isBaseCurrency", "=", true)
    .executeTakeFirst();

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