import type { FormErrors } from '../types';

export function validateExchangeForm(data: {
  code: string;
  name: string;
  country: string;
  currency: string;
}): FormErrors {
  const errors: FormErrors = {};

  if (!data.code.trim()) {
    errors.code = 'Exchange code is required';
  } else if (data.code.length > 10) {
    errors.code = 'Exchange code must be 10 characters or less';
  }

  if (!data.name.trim()) {
    errors.name = 'Exchange name is required';
  }

  if (!data.country.trim()) {
    errors.country = 'Country is required';
  } else if (data.country.length !== 2) {
    errors.country = 'Country must be exactly 2 characters (e.g., US, CA, GB)';
  }

  if (!data.currency.trim()) {
    errors.currency = 'Currency is required';
  } else if (data.currency.length !== 3) {
    errors.currency = 'Currency must be exactly 3 characters (e.g., USD, EUR, CAD)';
  }

  return errors;
}

export function hasValidationErrors(errors: FormErrors): boolean {
  return Object.keys(errors).length > 0;
}
