/**
 * Fehlercodes für die API
 * Diese Codes werden an das Frontend gesendet und dort übersetzt
 * 
 * Format: { code: string, params?: object }
 * 
 * Beispiel:
 * - { code: 'ERROR_USER_NOT_FOUND' }
 * - { code: 'ERROR_MEMBER_NOT_FOUND', params: { memberId: 123 } }
 * - { code: 'ERROR_VALIDATION_FAILED', params: { field: 'email', value: 'invalid' } }
 */

export const ERROR_CODES = {
  // Allgemeine Fehler
  INTERNAL_SERVER_ERROR: 'ERROR_INTERNAL_SERVER_ERROR',
  UNKNOWN_ERROR: 'ERROR_UNKNOWN_ERROR',
  VALIDATION_FAILED: 'ERROR_VALIDATION_FAILED',
  NOT_FOUND: 'ERROR_NOT_FOUND',
  UNAUTHORIZED: 'ERROR_UNAUTHORIZED',
  FORBIDDEN: 'ERROR_FORBIDDEN',
  BAD_REQUEST: 'ERROR_BAD_REQUEST',
  
  // Authentifizierung
  USER_NOT_FOUND: 'ERROR_USER_NOT_FOUND',
  INVALID_PASSWORD: 'ERROR_INVALID_PASSWORD',
  LOGIN_FAILED: 'ERROR_LOGIN_FAILED',
  SESSION_EXPIRED: 'ERROR_SESSION_EXPIRED',
  
  // MyTischtennis
  MYTISCHTENNIS_USER_NOT_FOUND: 'ERROR_MYTISCHTENNIS_USER_NOT_FOUND',
  MYTISCHTENNIS_INVALID_PASSWORD: 'ERROR_MYTISCHTENNIS_INVALID_PASSWORD',
  MYTISCHTENNIS_LOGIN_FAILED: 'ERROR_MYTISCHTENNIS_LOGIN_FAILED',
  MYTISCHTENNIS_ACCOUNT_NOT_LINKED: 'ERROR_MYTISCHTENNIS_ACCOUNT_NOT_LINKED',
  MYTISCHTENNIS_PASSWORD_NOT_SAVED: 'ERROR_MYTISCHTENNIS_PASSWORD_NOT_SAVED',
  MYTISCHTENNIS_SESSION_EXPIRED: 'ERROR_MYTISCHTENNIS_SESSION_EXPIRED',
  MYTISCHTENNIS_NO_PASSWORD_SAVED: 'ERROR_MYTISCHTENNIS_NO_PASSWORD_SAVED',
  MYTISCHTENNIS_CAPTCHA_REQUIRED: 'ERROR_MYTISCHTENNIS_CAPTCHA_REQUIRED',
  
  // Mitglieder
  MEMBER_NOT_FOUND: 'ERROR_MEMBER_NOT_FOUND',
  MEMBER_ALREADY_EXISTS: 'ERROR_MEMBER_ALREADY_EXISTS',
  MEMBER_FIRSTNAME_REQUIRED: 'ERROR_MEMBER_FIRSTNAME_REQUIRED',
  MEMBER_LASTNAME_REQUIRED: 'ERROR_MEMBER_LASTNAME_REQUIRED',
  
  // Gruppen
  GROUP_NOT_FOUND: 'ERROR_GROUP_NOT_FOUND',
  GROUP_NAME_REQUIRED: 'ERROR_GROUP_NAME_REQUIRED',
  GROUP_ALREADY_EXISTS: 'ERROR_GROUP_ALREADY_EXISTS',
  GROUP_INVALID_PRESET_TYPE: 'ERROR_GROUP_INVALID_PRESET_TYPE',
  GROUP_CANNOT_RENAME_PRESET: 'ERROR_GROUP_CANNOT_RENAME_PRESET',
  
  // Turniere
  TOURNAMENT_NOT_FOUND: 'ERROR_TOURNAMENT_NOT_FOUND',
  TOURNAMENT_NO_DATE: 'ERROR_TOURNAMENT_NO_DATE',
  TOURNAMENT_CLASS_NAME_REQUIRED: 'ERROR_TOURNAMENT_CLASS_NAME_REQUIRED',
  TOURNAMENT_NO_PARTICIPANTS: 'ERROR_TOURNAMENT_NO_PARTICIPANTS',
  TOURNAMENT_NO_VALID_PARTICIPANTS: 'ERROR_TOURNAMENT_NO_VALID_PARTICIPANTS',
  TOURNAMENT_NO_TRAINING_DAY: 'ERROR_TOURNAMENT_NO_TRAINING_DAY',
  TOURNAMENT_PDF_GENERATION_FAILED: 'ERROR_TOURNAMENT_PDF_GENERATION_FAILED',
  TOURNAMENT_SELECT_FIRST: 'ERROR_TOURNAMENT_SELECT_FIRST',
  
  // Trainingstagebuch
  DIARY_DATE_NOT_FOUND: 'ERROR_DIARY_DATE_NOT_FOUND',
  DIARY_DATE_UPDATED: 'ERROR_DIARY_DATE_UPDATED',
  DIARY_NO_PARTICIPANTS: 'ERROR_DIARY_NO_PARTICIPANTS',
  DIARY_PDF_GENERATION_FAILED: 'ERROR_DIARY_PDF_GENERATION_FAILED',
  DIARY_IMAGE_LOAD_FAILED: 'ERROR_DIARY_IMAGE_LOAD_FAILED',
  DIARY_STATS_LOAD_FAILED: 'ERROR_DIARY_STATS_LOAD_FAILED',
  DIARY_NO_EXERCISE_DATA: 'ERROR_DIARY_NO_EXERCISE_DATA',
  DIARY_ACTIVITY_PARTICIPANTS_UPDATE_FAILED: 'ERROR_DIARY_ACTIVITY_PARTICIPANTS_UPDATE_FAILED',
  DIARY_GROUP_ASSIGNMENT_UPDATED: 'SUCCESS_DIARY_GROUP_ASSIGNMENT_UPDATED',
  DIARY_GROUP_ASSIGNMENT_UPDATE_FAILED: 'ERROR_DIARY_GROUP_ASSIGNMENT_UPDATE_FAILED',
  DIARY_ASSIGN_ALL_PARTICIPANTS_FAILED: 'ERROR_DIARY_ASSIGN_ALL_PARTICIPANTS_FAILED',
  DIARY_ASSIGN_GROUP_FAILED: 'ERROR_DIARY_ASSIGN_GROUP_FAILED',
  DIARY_PARTICIPANT_ASSIGN_FAILED: 'ERROR_DIARY_PARTICIPANT_ASSIGN_FAILED',
  DIARY_PARTICIPANT_GROUP_ASSIGNMENT_UPDATE_FAILED: 'ERROR_DIARY_PARTICIPANT_GROUP_ASSIGNMENT_UPDATE_FAILED',
  DIARY_MEMBER_CREATED: 'SUCCESS_DIARY_MEMBER_CREATED',
  DIARY_MEMBER_CREATE_FAILED: 'ERROR_DIARY_MEMBER_CREATE_FAILED',
  
  // Team Management
  TEAM_NOT_LINKED_TO_LEAGUE: 'ERROR_TEAM_NOT_LINKED_TO_LEAGUE',
  TEAM_LINK_TO_LEAGUE_REQUIRED: 'ERROR_TEAM_LINK_TO_LEAGUE_REQUIRED',
  TEAM_PDF_LOAD_FAILED: 'ERROR_TEAM_PDF_LOAD_FAILED',
  TEAM_STATS_LOAD_FAILED: 'ERROR_TEAM_STATS_LOAD_FAILED',
  
  // Aktivitäten
  ACTIVITY_IMAGE_DELETE_FAILED: 'ERROR_ACTIVITY_IMAGE_DELETE_FAILED',
  
  // Offizielle Turniere
  OFFICIAL_TOURNAMENT_PDF_UPLOAD_SUCCESS: 'SUCCESS_OFFICIAL_TOURNAMENT_PDF_UPLOAD',
  OFFICIAL_TOURNAMENT_PDF_UPLOAD_FAILED: 'ERROR_OFFICIAL_TOURNAMENT_PDF_UPLOAD',
  
  // Vereine
  CLUB_NOT_FOUND: 'ERROR_CLUB_NOT_FOUND',
  CLUB_ALREADY_EXISTS: 'ERROR_CLUB_ALREADY_EXISTS',
  CLUB_NAME_REQUIRED: 'ERROR_CLUB_NAME_REQUIRED',
  CLUB_NAME_TOO_SHORT: 'ERROR_CLUB_NAME_TOO_SHORT',
  
  // Mitglieder-Übertragung
  MEMBER_TRANSFER_BULK_FAILED: 'ERROR_MEMBER_TRANSFER_BULK_FAILED',
  
  // Training
  TRAINING_STATS_LOAD_FAILED: 'ERROR_TRAINING_STATS_LOAD_FAILED',
  
  // Logs
  LOG_NOT_FOUND: 'ERROR_LOG_NOT_FOUND',
};

/**
 * Erstellt ein Fehler-Objekt mit Code und optionalen Parametern
 * @param {string} code - Fehlercode aus ERROR_CODES
 * @param {object} params - Optionale Parameter für die Fehlermeldung
 * @returns {object} Fehler-Objekt mit code und params
 */
export function createError(code, params = null) {
  return {
    code,
    ...(params && { params })
  };
}

