import type { AiSearchErrorConfig } from '@redocly/theme/core/types';

export enum AiSearchError {
  Unauthorized = 'ai_search_unauthorized',
  Forbidden = 'ai_search_forbidden',
  HttpRequestFailed = 'http_request_in_failed_status',
  EmptyResponse = 'empty_response',
  ErrorProcessingResponse = 'error_processing_response',
}
export const enum AiSearchConversationRole {
  USER = 'user',
  ASSISTANT = 'assistant',
}

const defaultErrorConfig: AiSearchErrorConfig = {
  headerKey: 'search.ai.error.header',
  headerDefault: 'Oops! Something went wrong.',
  messageKey: 'search.ai.error.description',
  messageDefault:
    'We encountered an issue while processing your search. Try again later or refine your query. If the problem persists, please contact Redocly support.',
};

export const AI_SEARCH_ERROR_CONFIG: Record<AiSearchError, AiSearchErrorConfig> = {
  [AiSearchError.Forbidden]: {
    headerKey: 'search.ai.error.header.forbidden',
    headerDefault: 'Feature Unavailable',
    messageKey: 'search.ai.error.description.forbidden',
    messageDefault: 'AI Search is currently unavailable.',
  },
  [AiSearchError.Unauthorized]: {
    headerKey: 'search.ai.error.header.unauthorized',
    headerDefault: 'Authentication Required',
    messageKey: 'search.ai.error.description.unauthorized',
    messageDefault: 'You are not authorized to use AI Search.',
  },
  [AiSearchError.HttpRequestFailed]: defaultErrorConfig,
  [AiSearchError.EmptyResponse]: defaultErrorConfig,
  [AiSearchError.ErrorProcessingResponse]: defaultErrorConfig,
} as const;
