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

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

export function createRoleType<const F extends Record<string, TailorAnyDBField>>(
  params: CreateRoleTypeParams<F>,
) {
  return db
    .type("Role", {
      name: db.string().unique().description("Role name (unique identifier)"),
      description: db
        .string({ optional: true })
        .description("Optional description of what this role represents"),
      ...((params.fields ?? {}) as F),
      ...db.fields.timestamps(),
    })
    .permission(unsafeAllowAllTypePermission)
    .gqlPermission(unsafeAllowAllGqlPermission);
}

export const role = createRoleType({});
