const toBoolean = (value, fallback = false) => {
  if (typeof value === 'boolean') return value;
  if (typeof value === 'string') {
    const normalized = value.trim().toLowerCase();
    if (['true', '1', 'yes', 'on'].includes(normalized)) return true;
    if (['false', '0', 'no', 'off'].includes(normalized)) return false;
  }
  return fallback;
};

const resolveLocales = (rawLocales) => {
  if (!rawLocales) {
    return ['en', 'tr'];
  }
  const locales = rawLocales
    .split(',')
    .map((locale) => locale.trim().toLowerCase())
    .filter((locale) => ['en', 'tr'].includes(locale));
  return locales.length ? [...new Set(locales)] : ['en', 'tr'];
};

const toInteger = (value, fallback) => {
  const parsed = parseInt(value, 10);
  return Number.isNaN(parsed) ? fallback : parsed;
};

module.exports = {
  toBoolean,
  resolveLocales,
  toInteger
};
