/**
 * API Key Management Types
 *
 * TypeScript interfaces and types for API key functionality
 */

import React from 'react';

/**
 * Information about an API key extracted from validation response
 */
export interface ApiKeyInfo {
  organizationSlug?: string;
  projectSlug?: string;
}

/**
 * Response from API info endpoint
 */
export interface ApiInfoResponse {
  message?: string;
  keyInfo?: {
    organizationSlug?: string;
    organizationId?: string;
    projectSlug?: string;
    projectId?: string;
  };
}

/**
 * Result of API key validation
 */
export interface ValidationResult {
  success: boolean;
  keyInfo?: ApiKeyInfo;
  error?: string;
}

/**
 * Context value for API Key Provider
 */
export interface ApiKeyContextValue {
  // Data State
  apiKey: string;
  apiKeyValidated: boolean;
  apiKeyInfo: ApiKeyInfo | null;
  apiKeyError: string;
  validatingKey: boolean;
  isReady: boolean; // true when initial validation complete

  // UI State (grouped)
  ui: {
    expanded: boolean;
    keyVisible: boolean;
  };

  // Actions
  setApiKey: (key: string) => void;
  validateApiKey: () => Promise<void>;
  revokeApiKey: (clearPageState?: () => void) => void;
  toggleKeyVisibility: () => void;
  setExpanded: (expanded: boolean) => void;

  // Focus method for external components
  focus: () => void;
  inputRef: React.RefObject<HTMLInputElement | null>;
  containerRef: React.RefObject<HTMLDivElement | null>;
}

/**
 * Props for ApiKeyProvider component
 */
export interface ApiKeyProviderProps {
  children: React.ReactNode;
  onValidationSuccess?: (keyInfo: ApiKeyInfo) => void;
}
