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

export interface GetCostElementInput {
  id: string;
}

/**
 * Function: getCostElement
 *
 * Retrieves a single cost element by id.
 */
export async function run(db: ReadonlyDB<DB>, input: GetCostElementInput) {
  const result = await db
    .selectFrom("CostElement")
    .selectAll()
    .where("id", "=", input.id)
    .executeTakeFirst();

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