/** Stable API error codes — frontend maps these to translated user messages. */
export const ErrorCode = {
  // Auth
  AUTH_INVALID_CREDENTIALS: 'AUTH_INVALID_CREDENTIALS',
  AUTH_UNAUTHORIZED: 'AUTH_UNAUTHORIZED',
  AUTH_REFRESH_TOKEN_NOT_FOUND: 'AUTH_REFRESH_TOKEN_NOT_FOUND',
  AUTH_REFRESH_TOKEN_INVALID: 'AUTH_REFRESH_TOKEN_INVALID',
  AUTH_SESSION_EXPIRED: 'AUTH_SESSION_EXPIRED',
  AUTH_USER_NOT_FOUND: 'AUTH_USER_NOT_FOUND',
  AUTH_ORG_NOT_SELECTED: 'AUTH_ORG_NOT_SELECTED',
  AUTH_ORG_ACCESS_DENIED: 'AUTH_ORG_ACCESS_DENIED',
  AUTH_INVITATION_PENDING: 'AUTH_INVITATION_PENDING',
  AUTH_REGISTRATION_EMAIL_EXISTS: 'AUTH_REGISTRATION_EMAIL_EXISTS',
  AUTH_REGISTRATION_MOBILE_EXISTS: 'AUTH_REGISTRATION_MOBILE_EXISTS',
  AUTH_REGISTRATION_MOBILE_INVALID: 'AUTH_REGISTRATION_MOBILE_INVALID',
  AUTH_REGISTRATION_FAILED: 'AUTH_REGISTRATION_FAILED',
  AUTH_PASSWORD_INCORRECT: 'AUTH_PASSWORD_INCORRECT',
  AUTH_PASSWORD_RESET_EXPIRED: 'AUTH_PASSWORD_RESET_EXPIRED',
  AUTH_VERIFICATION_CODE_INVALID: 'AUTH_VERIFICATION_CODE_INVALID',
  AUTH_VERIFICATION_RATE_LIMIT: 'AUTH_VERIFICATION_RATE_LIMIT',
  AUTH_SELECT_ORG_FIRST: 'AUTH_SELECT_ORG_FIRST',
  AUTH_CREATE_ORG_OWNER_ONLY: 'AUTH_CREATE_ORG_OWNER_ONLY',
  AUTH_PASSWORD_CURRENT_REQUIRED: 'AUTH_PASSWORD_CURRENT_REQUIRED',

  // Permission
  PERMISSION_DENIED: 'PERMISSION_DENIED',
  PERMISSION_ORG_MANAGE: 'PERMISSION_ORG_MANAGE',
  PERMISSION_CLINIC_ONLY: 'PERMISSION_CLINIC_ONLY',
  PERMISSION_LAB_ONLY: 'PERMISSION_LAB_ONLY',
  PERMISSION_NOT_MEMBER: 'PERMISSION_NOT_MEMBER',
  PERMISSION_OWNER_ONLY: 'PERMISSION_OWNER_ONLY',
  PERMISSION_PARTICIPATION_SUBSCRIPTION: 'PERMISSION_PARTICIPATION_SUBSCRIPTION',
  PERMISSION_ENABLE_PARTICIPATION_FIRST: 'PERMISSION_ENABLE_PARTICIPATION_FIRST',
  PERMISSION_CLINIC_WORKING_HOURS: 'PERMISSION_CLINIC_WORKING_HOURS',
  PERMISSION_ACCESS_APPOINTMENTS: 'PERMISSION_ACCESS_APPOINTMENTS',
  PERMISSION_EDIT_APPOINTMENTS: 'PERMISSION_EDIT_APPOINTMENTS',
  PERMISSION_ACCESS_TREATMENTS: 'PERMISSION_ACCESS_TREATMENTS',
  PERMISSION_EDIT_TREATMENTS: 'PERMISSION_EDIT_TREATMENTS',
  PERMISSION_ACCESS_TASKS: 'PERMISSION_ACCESS_TASKS',
  PERMISSION_EDIT_TASKS: 'PERMISSION_EDIT_TASKS',
  PERMISSION_ACCESS_CASES: 'PERMISSION_ACCESS_CASES',
  PERMISSION_ACCESS_STAFF: 'PERMISSION_ACCESS_STAFF',
  PERMISSION_EDIT_STAFF: 'PERMISSION_EDIT_STAFF',
  PERMISSION_ORG_NOT_FOUND: 'PERMISSION_ORG_NOT_FOUND',
  LAB_CASE_ACCESS_DENIED: 'LAB_CASE_ACCESS_DENIED',

  // Validation
  VALIDATION_FAILED: 'VALIDATION_FAILED',
  VALIDATION_EMAIL_INVALID: 'VALIDATION_EMAIL_INVALID',
  VALIDATION_PASSWORD_TOO_SHORT: 'VALIDATION_PASSWORD_TOO_SHORT',
  VALIDATION_PASSWORD_REQUIRED: 'VALIDATION_PASSWORD_REQUIRED',
  VALIDATION_MOBILE_INVALID: 'VALIDATION_MOBILE_INVALID',
  VALIDATION_NAME_TOO_SHORT: 'VALIDATION_NAME_TOO_SHORT',
  VALIDATION_ORGANIZATION_NAME_REQUIRED: 'VALIDATION_ORGANIZATION_NAME_REQUIRED',
  VALIDATION_ORGANIZATION_TYPE_INVALID: 'VALIDATION_ORGANIZATION_TYPE_INVALID',
  VALIDATION_TOKEN_REQUIRED: 'VALIDATION_TOKEN_REQUIRED',
  VALIDATION_FIELD_REQUIRED: 'VALIDATION_FIELD_REQUIRED',
  VALIDATION_LANGUAGE_INVALID: 'VALIDATION_LANGUAGE_INVALID',
  VALIDATION_INVALID_REQUEST: 'VALIDATION_INVALID_REQUEST',

  // Generic HTTP
  NOT_FOUND: 'NOT_FOUND',
  CONFLICT: 'CONFLICT',
  CONFLICT_FUTURE_APPOINTMENTS: 'CONFLICT_FUTURE_APPOINTMENTS',
  APPOINTMENT_PATIENT_LOCKED: 'APPOINTMENT_PATIENT_LOCKED',
  APPOINTMENT_HAS_TREATMENT: 'APPOINTMENT_HAS_TREATMENT',
  TREATMENT_DETAIL_SENT: 'TREATMENT_DETAIL_SENT',
  BAD_REQUEST: 'BAD_REQUEST',
  INTERNAL_ERROR: 'INTERNAL_ERROR',
} as const;

export type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];

export interface ValidationErrorDetail {
  field: string;
  code: ErrorCodeValue;
}
