/* eslint-disable @typescript-eslint/no-unused-vars */

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",
  },
  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",
  },
  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",
  },
  CACHE: {
    DELETE_ERROR: "CACHE_DELETE_ERROR",
    SAVE_ERROR: "CACHE_SAVE_ERROR",
    LOAD_ERROR: "CACHE_LOAD_ERROR",
    CLEAR_ERROR: "CACHE_CLEAR_ERROR",
    MODE_FETCH_ERROR: "CACHE_MODE_FETCH_ERROR",
    MODE_UPDATE_ERROR: "CACHE_MODE_UPDATE_ERROR",
    INVALID_MODE: "CACHE_INVALID_MODE",
  },
  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",
  },
  DEBUG: {
    FETCH_ERROR: "DEBUG_FETCH_ERROR",
    SAVE_ERROR: "DEBUG_SAVE_ERROR",
    CLEAR_ERROR: "DEBUG_CLEAR_ERROR",
  },
  CLIENT: {
    FETCH_ERROR: "CLIENT_FETCH_ERROR",
    NETWORK_ERROR: "CLIENT_NETWORK_ERROR",
    REQUEST_FAILED: "CLIENT_REQUEST_FAILED",
  },
} 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>;
