 

export const ERROR_CODES = {
  MONGODB: {
    MISSING_URI: "MONGODB_MISSING_URI",
    CONNECTION_FAILED: "MONGODB_CONNECTION_FAILED",
  },
  AUTH: {
    UNAUTHENTICATED: "AUTH_UNAUTHENTICATED",
    INVALID_CREDENTIALS: "AUTH_INVALID_CREDENTIALS",
    PASSWORD_NOT_STRONG: "AUTH_PASSWORD_NOT_STRONG",
    PASSWORD_MISMATCH: "AUTH_PASSWORD_MISMATCH",
    EMAIL_EXISTS: "AUTH_EMAIL_EXISTS",
    INVALID_USER_DATA: "AUTH_INVALID_USER_DATA",
    LOGOUT_ERROR: "AUTH_LOGOUT_ERROR",
    REGISTRATION_FAILED: "AUTH_REGISTRATION_FAILED",
    USER_NOT_FOUND: "AUTH_USER_NOT_FOUND",
    INVALID_PASSWORD: "AUTH_INVALID_PASSWORD",
    PASSWORD_CHANGE_ERROR: "AUTH_PASSWORD_CHANGE_ERROR",
    FETCH_ERROR: "AUTH_FETCH_ERROR",
    FORBIDDEN: "AUTH_FORBIDDEN",
  },
  KOMGA: {
    MISSING_CONFIG: "KOMGA_MISSING_CONFIG",
    MISSING_CREDENTIALS: "KOMGA_MISSING_CREDENTIALS",
    CONNECTION_ERROR: "KOMGA_CONNECTION_ERROR",
    HTTP_ERROR: "KOMGA_HTTP_ERROR",
    SERVER_UNREACHABLE: "KOMGA_SERVER_UNREACHABLE",
  },
  CONFIG: {
    SAVE_ERROR: "CONFIG_SAVE_ERROR",
    FETCH_ERROR: "CONFIG_FETCH_ERROR",
    TTL_SAVE_ERROR: "CONFIG_TTL_SAVE_ERROR",
    TTL_FETCH_ERROR: "CONFIG_TTL_FETCH_ERROR",
  },
  LIBRARY: {
    NOT_FOUND: "LIBRARY_NOT_FOUND",
    FETCH_ERROR: "LIBRARY_FETCH_ERROR",
    SCAN_ERROR: "LIBRARY_SCAN_ERROR",
  },
  SERIES: {
    FETCH_ERROR: "SERIES_FETCH_ERROR",
    NO_BOOKS_FOUND: "SERIES_NO_BOOKS_FOUND",
  },
  BOOK: {
    NOT_FOUND: "BOOK_NOT_FOUND",
    PROGRESS_UPDATE_ERROR: "BOOK_PROGRESS_UPDATE_ERROR",
    PROGRESS_DELETE_ERROR: "BOOK_PROGRESS_DELETE_ERROR",
    PAGES_FETCH_ERROR: "BOOK_PAGES_FETCH_ERROR",
    DOWNLOAD_CANCELLED: "BOOK_DOWNLOAD_CANCELLED",
  },
  FAVORITE: {
    ADD_ERROR: "FAVORITE_ADD_ERROR",
    DELETE_ERROR: "FAVORITE_DELETE_ERROR",
    FETCH_ERROR: "FAVORITE_FETCH_ERROR",
    UPDATE_ERROR: "FAVORITE_UPDATE_ERROR",
    NETWORK_ERROR: "FAVORITE_NETWORK_ERROR",
    SERVER_ERROR: "FAVORITE_SERVER_ERROR",
    STATUS_CHECK_ERROR: "FAVORITE_STATUS_CHECK_ERROR",
  },
  PREFERENCES: {
    FETCH_ERROR: "PREFERENCES_FETCH_ERROR",
    UPDATE_ERROR: "PREFERENCES_UPDATE_ERROR",
    CONTEXT_ERROR: "PREFERENCES_CONTEXT_ERROR",
  },
  UI: {
    TABS_TRIGGER_ERROR: "UI_TABS_TRIGGER_ERROR",
    TABS_CONTENT_ERROR: "UI_TABS_CONTENT_ERROR",
  },
  IMAGE: {
    FETCH_ERROR: "IMAGE_FETCH_ERROR",
  },
  HOME: {
    FETCH_ERROR: "HOME_FETCH_ERROR",
  },
  MIDDLEWARE: {
    UNAUTHORIZED: "MIDDLEWARE_UNAUTHORIZED",
    INVALID_TOKEN: "MIDDLEWARE_INVALID_TOKEN",
    INVALID_SESSION: "MIDDLEWARE_INVALID_SESSION",
  },
  CLIENT: {
    FETCH_ERROR: "CLIENT_FETCH_ERROR",
    NETWORK_ERROR: "CLIENT_NETWORK_ERROR",
    REQUEST_FAILED: "CLIENT_REQUEST_FAILED",
  },
  ADMIN: {
    FETCH_USERS_ERROR: "ADMIN_FETCH_USERS_ERROR",
    UPDATE_USER_ERROR: "ADMIN_UPDATE_USER_ERROR",
    DELETE_USER_ERROR: "ADMIN_DELETE_USER_ERROR",
    FETCH_STATS_ERROR: "ADMIN_FETCH_STATS_ERROR",
    CANNOT_DELETE_SELF: "ADMIN_CANNOT_DELETE_SELF",
    RESET_PASSWORD_ERROR: "ADMIN_RESET_PASSWORD_ERROR",
    CANNOT_RESET_OWN_PASSWORD: "ADMIN_CANNOT_RESET_OWN_PASSWORD",
  },
} as const;

type Values<T> = T[keyof T];
type ErrorCodeValues<T> = T extends { [key: string]: infer U }
  ? U extends { [key: string]: string }
    ? Values<U>
    : never
  : never;

export type ErrorCode = ErrorCodeValues<typeof ERROR_CODES>;
