import {
  db,
  type TailorAnyDBField,
  unsafeAllowAllGqlPermission,
  unsafeAllowAllTypePermission,
} from "@tailor-platform/sdk";

export interface CreateUoMCategoryTypeParams<F extends Record<string, TailorAnyDBField>> {
  fields?: F;
}

export function createUoMCategoryType<const F extends Record<string, TailorAnyDBField>>(
  params: CreateUoMCategoryTypeParams<F>,
) {
  return db
    .type("UoMCategory", {
      name: db.string().unique().description("Category name (e.g., Weight, Volume, Length)"),
      description: db
        .string({ optional: true })
        .description("Optional description of the category"),
      referenceUnitId: db
        .uuid({ optional: true })
        .description("Foreign key to the reference Unit for conversions"),
      isActive: db.bool().description("Whether the category is active"),
      ...((params.fields ?? {}) as F),
      ...db.fields.timestamps(),
    })
    .permission(unsafeAllowAllTypePermission)
    .gqlPermission(unsafeAllowAllGqlPermission);
}

export const uomCategory = createUoMCategoryType({});
