import { defaultGqlPermission, defaultPermission } from "@tailor-platform/erp-kit/core";
import { db } from "@tailor-platform/sdk";
import { manufacturingCostSummary } from "./manufacturingCostSummary";

export function createManufacturingCostLineType() {
  return db
    .type("ManufacturingCostLine", {
      costSummaryId: db
        .uuid()
        .relation({
          type: "n-1",
          toward: { type: manufacturingCostSummary },
          backward: "costLines",
        })
        .description("Foreign key to ManufacturingCostSummary"),
      costType: db.string().description("Cost type: e.g. MATERIAL, LABOR, MACHINE, OVERHEAD"),
      plannedAmount: db.float().description("Planned cost amount"),
      actualAmount: db.float().description("Actual cost amount"),
      ...db.fields.timestamps(),
    })
    .permission(defaultPermission)
    .gqlPermission(defaultGqlPermission);
}

export const manufacturingCostLine = createManufacturingCostLineType();
