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

export interface GetInternalOrderInput {
  id: string;
}

/**
 * Function: getInternalOrder
 *
 * Retrieves a single internal order by id.
 */
export async function run(db: ReadonlyDB<DB>, input: GetInternalOrderInput) {
  const result = await db
    .selectFrom("InternalOrder")
    .selectAll()
    .where("id", "=", input.id)
    .executeTakeFirst();

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