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

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

export function createProductAttributeType<const F extends Record<string, TailorAnyDBField>>(
  params: CreateProductAttributeTypeParams<F>,
) {
  return db
    .type("ProductAttribute", {
      code: db.string().unique().description("Globally unique, immutable attribute code"),
      name: db.string().description("Attribute display name"),
      ...((params.fields ?? {}) as F),
      ...db.fields.timestamps(),
    })
    .permission(unsafeAllowAllTypePermission)
    .gqlPermission(unsafeAllowAllGqlPermission);
}

export const productAttribute = createProductAttributeType({});
