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

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(defaultPermission)
    .gqlPermission(defaultGqlPermission);
}

export const productAttribute = createProductAttributeType({});
