import {
  type InitialDepositRemarkKind,
  type InitialDepositOperator,
  resolveInitialDepositRemark,
} from '@thebet365/shared';
import { FormValidationError } from '../i18n/form-validation';

export function buildInitialDepositRemark(
  initialDeposit: number,
  kind: InitialDepositRemarkKind | '',
  custom: string,
  operator: InitialDepositOperator,
): string | undefined {
  if (initialDeposit <= 0) return undefined;
  if (!kind) throw new FormValidationError('err.initial_deposit_kind_required');
  try {
    return resolveInitialDepositRemark(kind, custom, operator);
  } catch {
    throw new FormValidationError('err.initial_deposit_custom_required');
  }
}
