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

export interface GetShipmentInput {
  id: string;
}

export async function run(db: ReadonlyDB<DB>, input: GetShipmentInput) {
  const aggregate = await loadShipmentAggregate(db, input.id);
  return ok({ shipment: aggregate ? { ...aggregate.shipment, lines: aggregate.lines } : null });
}
