/**
 * Copyright IBM Corp. 2024, 2025
 */

import { APICFileInfo } from '../../apic-mode/models/apic-file-info.model.js';
import { IRange } from '../../common/models/lint-range.model.js';
import { IlintResponse } from '../../common/models/lint-response.model.js';
import { VCSFileInfo } from '../../vcs/models/vcs-file-info.model.js';
import { AiCodeAugmentations } from '../models/ai-augmentations.model.js';
import {
  AiErrorRemediationDiffs,
  AiErrorRemediations,
  CommonLintResponse,
} from '../models/ai-error-remediations.model.js';
import { ApiMConfig } from '../models/api-m-config.model.js';

export interface IAiDataHandler {
  getApiMConfig: () => Promise<ApiMConfig | null>;
  validateApiMInstance: (apiMConfig: ApiMConfig) => Promise<boolean>;
  getApiFileKey: (parentFolderAlias: string, filePath: string) => string;
  generateAiEnhancements: (
    file: VCSFileInfo | FileSystemFileHandle | APICFileInfo,
    apiMConfig: ApiMConfig,
  ) => Promise<AiCodeAugmentations>;
  
  /**
   * Process AI enhancements result to add range information
   * This can be used with results from API calls or from event data
   * @param fileContent The content of the file
   * @param result The result containing suggestions and diffs
   * @returns Processed AI code augmentations
   */
  processAiEnhancementsResult: (
    fileContent: string,
    result: any,
  ) => AiCodeAugmentations;
  /**
   *
   * @param file
   * @param completeFilePath
   * @param aiEnhancements
   * @returns updated file content
   */
  applyAiEnhancements: (
    file: VCSFileInfo | FileSystemFileHandle | APICFileInfo,
    completeFilePath: string,
    aiCodeAugmentations: AiCodeAugmentations,
    specPathsToBeApplied: string[],
  ) => Promise<string>;

  getRange(
    file: VCSFileInfo | FileSystemFileHandle | APICFileInfo,
    paths: Array<string>,
  ): Promise<Map<string, IRange>>;

  generateObjectRange(
    file: VCSFileInfo | FileSystemFileHandle | APICFileInfo,
    paths: Array<string>,
    isYaml: boolean,
  ): Promise<IRange[]>;

  generateAiErrorRemediations: (
    file: VCSFileInfo | FileSystemFileHandle | APICFileInfo,
    apiMConfig: ApiMConfig,
  ) => Promise<AiErrorRemediations>;
  
  /**
   * Process AI error remediations result to add range information
   * This can be used with results from API calls or from event data
   * @param fileContent The content of the file
   * @param result The result containing updatedOpenApi and diffs
   * @returns Processed AI error remediations
   */
  processAiErrorRemediationsResult: (
    fileContent: string,
    result: any,
  ) => AiErrorRemediations;

  // generateAiErrorRemediations // returns a list of Diffs object with all the data
  combineSpectralAndAiRuleRemediations(
    lintResponses: IlintResponse[],
    aiErrorRemediationDiffs: AiErrorRemediationDiffs,
  ): CommonLintResponse[];
  /**
   *
   * @param file
   * @param completeFilePath
   * @param aiErrorRemediationData
   * @returns updated file content
   */

  applyAiErrorRemediations: (
    file: VCSFileInfo | FileSystemFileHandle | APICFileInfo,
    completeFilePath: string,
    aiErrorRemediations: AiErrorRemediations,
    specPathsToBeApplied: string[],
  ) => Promise<string>;
  
  /**
   * Process validation errors to add accurate range information
   * This can be used with results from ruleset validation
   * @param fileContent The content of the file
   * @param validationErrors The validation errors to process
   * @returns Processed validation errors as lint responses
   */
  processValidationErrors: (
    fileContent: string,
    validationErrors: any[],
  ) => IlintResponse[];
  
  /**
   * Process and apply validation errors to the editor
   * @param file The file handle (VCS, local, or APIC)
   * @param fileContent The content of the file
   * @param validationErrors The validation errors to process
   * @param selectedRulesets Optional array of selected rulesets
   * @returns Promise resolving to combined lint responses
   */
  processAndCombineValidationErrors: (
    file: VCSFileInfo | FileSystemFileHandle | APICFileInfo,
    fileContent: string,
    validationErrors: any[],
    selectedRulesets?: any[]
  ) => Promise<IlintResponse[]>;
}