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

export interface GetFiscalYearInput {
  id: string;
}

/**
 * Function: getFiscalYear
 *
 * Retrieves a single fiscal year by id.
 */
export async function run(db: ReadonlyDB<DB>, input: GetFiscalYearInput) {
  const result = await db
    .selectFrom("FiscalYear")
    .selectAll()
    .where("id", "=", input.id)
    .executeTakeFirst();

  return ok({ fiscalYear: result ?? null });
}
