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

export const changeDetail = db
  .type("ChangeDetail", {
    auditEntryId: db
      .uuid()
      .relation({
        type: "n-1",
        toward: { type: auditEntry },
        backward: "changeDetails",
      })
      .description("Foreign key to parent AuditEntry"),
    fieldName: db.string().description("Name of the field that changed"),
    oldValue: db
      .string({ optional: true })
      .description("Previous value (serialized string); null for CREATE operations"),
    newValue: db
      .string({ optional: true })
      .description("New value (serialized string); null for DELETE operations"),
    ...db.fields.timestamps(),
  })
  .permission(defaultPermission)
  .gqlPermission(defaultGqlPermission);
