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

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

export function createExchangeRateType<const F extends Record<string, TailorAnyDBField>>(
  params: CreateExchangeRateTypeParams<F>,
) {
  return db
    .type("ExchangeRate", {
      sourceCurrencyId: db.uuid().description("Foreign key to source Currency"),
      targetCurrencyId: db.uuid().description("Foreign key to target Currency"),
      rate: db.float().description("Conversion rate (source x rate = target)"),
      effectiveDate: db.date().description("Date from which this rate applies"),
      ...((params.fields ?? {}) as F),
      ...db.fields.timestamps(),
    })
    .permission(unsafeAllowAllTypePermission)
    .gqlPermission(unsafeAllowAllGqlPermission);
}

export const exchangeRate = createExchangeRateType({});
