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

export function createManufacturingCostSettlementRecordType() {
  return db
    .type("ManufacturingCostSettlementRecord", {
      costSummaryId: db
        .uuid()
        .relation({
          type: "n-1",
          toward: { type: manufacturingCostSummary },
          backward: "settlementRecords",
        })
        .description("Foreign key to ManufacturingCostSummary"),
      settlementDate: db.datetime().description("Date of settlement"),
      settlementReference: db.string().description("Reference identifier for the settlement"),
      acknowledgedDate: db
        .datetime({ optional: true })
        .description("Date when settlement was acknowledged"),
      ...db.fields.timestamps(),
    })
    .permission(defaultPermission)
    .gqlPermission(defaultGqlPermission);
}

export const manufacturingCostSettlementRecord = createManufacturingCostSettlementRecordType();
