interface ValidationInfo {
  message: string;
  action?: string;
  actionUrl?: string;
}

// Canonical SERP validation states. Key set must match AiKey's `validationInfoMap`
// — a drift guard in SerpKey.test.tsx asserts the two stay aligned.
export const validationInfoMap: Record<string, ValidationInfo> = {
  valid: {
    message: 'Your DataForSEO credentials are active and ready for SERP analysis.',
  },
  invalid_auth: {
    message:
      'DataForSEO rejected these credentials. Verify your login and password, or generate a new password from your DataForSEO dashboard.',
    action: 'Manage DataForSEO credentials',
    actionUrl: 'https://app.dataforseo.com/api-access',
  },
  quota_exceeded: {
    message:
      'Your DataForSEO account has run out of credits or hit a billing limit. Add funds or raise your spend limit to resume SERP analysis.',
    action: 'Manage DataForSEO billing',
    actionUrl: 'https://app.dataforseo.com/billing',
  },
  rate_limited: {
    message:
      'DataForSEO is rate-limiting your account; wait a few minutes or upgrade your plan.',
    action: 'Check rate limit docs',
    actionUrl: 'https://docs.dataforseo.com/v3/appendix/rate-limits/',
  },
  network_error: {
    message:
      'RankWizAI could not reach the DataForSEO API. This is usually a temporary network issue. Try validating again in a few minutes.',
  },
  provider_error: {
    message:
      'DataForSEO returned an unexpected error. Check the DataForSEO status page to see if there is an ongoing incident.',
    action: 'DataForSEO status page',
    actionUrl: 'https://status.dataforseo.com/',
  },
};

// Backend may emit the legacy `invalid_credentials` status from existing validation
// records. Normalize to the canonical `invalid_auth` so the lookup hits the new map
// without touching the SerpApiKeyService data column.
export const STATUS_ALIASES: Record<string, string> = {
  invalid_credentials: 'invalid_auth',
};
