import type { ConstraintJSON } from '~/shared/types/constraint'

export function constraintToHuman(constraint: ConstraintJSON): string {
  return constraint.natural_language_summary || formatConstraintFallback(constraint)
}

function formatConstraintFallback(c: ConstraintJSON): string {
  const params = c.params as Record<string, unknown>
  switch (c.type) {
    case 'max_hours_per_day':
      return `Maximal ${params.max_hours} Stunden pro Tag`
    case 'max_hours_per_week':
      return `Maximal ${params.max_hours} Stunden pro Woche`
    case 'min_rest_between_shifts':
      return `Mindestens ${params.min_hours} Stunden Ruhezeit zwischen Schichten`
    case 'max_consecutive_shifts':
      return `Maximal ${params.max_count} Schichten am Stück`
    case 'max_consecutive_shift_type':
      return `Maximal ${params.max_count} ${params.period_id}-Schichten am Stück`
    case 'forbidden_shift_sequence':
      return `${params.first_period_id}-Schicht darf nicht direkt auf ${params.second_period_id}-Schicht folgen`
    case 'employee_avoids_period':
      return `Mitarbeiter bevorzugt keine ${params.period_id}-Schichten`
    case 'employee_prefers_period':
      return `Mitarbeiter bevorzugt ${params.period_id}-Schichten`
    case 'fair_distribution':
      return `Faire Verteilung der ${params.metric === 'night_shifts' ? 'Nachtschichten' : 'Schichten'} (max. ${params.max_deviation_percent}% Abweichung)`
    default:
      return c.type.replace(/_/g, ' ')
  }
}
