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

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

export function createCurrencyType<const F extends Record<string, TailorAnyDBField>>(
  params: CreateCurrencyTypeParams<F>,
) {
  return db
    .type("Currency", {
      code: db.string().unique().description("ISO 4217 currency code (e.g., USD)"),
      name: db.string().description("Currency display name (e.g., US Dollar)"),
      symbol: db.string().description("Currency symbol (e.g., $)"),
      decimalPlaces: db.int().description("Number of decimal places (0-4)"),
      isBaseCurrency: db.bool().description("Whether this is the base currency"),
      isActive: db.bool().description("Whether the currency is active"),
      ...((params.fields ?? {}) as F),
      ...db.fields.timestamps(),
    })
    .permission(unsafeAllowAllTypePermission)
    .gqlPermission(unsafeAllowAllGqlPermission);
}

export const currency = createCurrencyType({});
