import { db, type TailorAnyDBField } from "@tailor-platform/sdk";
import { defaultGqlPermission, defaultPermission } from "../../../shared/modelPermissions";
import { uoMCategoryLifecycle } from "./uoMCategory.lifecycle.generated";

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"),
      status: db.enum(uoMCategoryLifecycle.states).description("Lifecycle status"),
      ...((params.fields ?? {}) as F),
      ...db.fields.timestamps(),
    })
    .permission(defaultPermission)
    .gqlPermission(defaultGqlPermission);
}

export const uomCategory = createUoMCategoryType({});
