/// <reference path="../../index.d.ts" />
import type { PublicLitElement as LitElement } from "@arcgis/lumina";
import type { T9nMeta } from "@arcgis/lumina/controllers";

export abstract class ArcgisSolutionsAssistant extends LitElement {
  /**
   * Contains the translations for this component.
   * All UI strings should be defined here.
   *
   * @internal
   */
  protected _translations: {
      betaTag: string;
      defaultStartUpMessage: string;
      defaultFollowUpQuestions: {
          engagePublic: string;
          howToDeploy: string;
          solutionsForEmergencies: string;
      };
      disclaimerMessage: string;
      genericErrorMessage: string;
      newConversationStarted: string;
      noPermissionTitle: string;
      noPermissionMessage: string;
      reportConcern: string;
      solutionsDocReference: string;
      solutionsDocReferences: string;
      sendMessage: string;
      solutionAssistantTitle: string;
      signIn: string;
      signInMessage: string;
      tooltips: {
          likeButton: string;
          dislikeButton: string;
          copyButton: string;
          newConversation: string;
          sendQuestion: string;
      };
      viewSolutionInApp: string;
  } & T9nMeta<{
      betaTag: string;
      defaultStartUpMessage: string;
      defaultFollowUpQuestions: {
          engagePublic: string;
          howToDeploy: string;
          solutionsForEmergencies: string;
      };
      disclaimerMessage: string;
      genericErrorMessage: string;
      newConversationStarted: string;
      noPermissionTitle: string;
      noPermissionMessage: string;
      reportConcern: string;
      solutionsDocReference: string;
      solutionsDocReferences: string;
      sendMessage: string;
      solutionAssistantTitle: string;
      signIn: string;
      signInMessage: string;
      tooltips: {
          likeButton: string;
          dislikeButton: string;
          copyButton: string;
          newConversation: string;
          sendQuestion: string;
      };
      viewSolutionInApp: string;
  }>;
  /**
   * Flag to open or close panel
   *
   * @default false
   */
  accessor open: boolean;
  /**
   * Define the AI server to access
   *
   * @default 'https://aiservices-beta.arcgis.com'
   */
  accessor serverRoot: string;
  /** Define the authentication for requests */
  accessor token: string | null;
  /**
   * First name of user for personal approach
   *
   * @default ''
   */
  accessor userFirstName: string;
  /**
   * Submits a query to the AI Assitant based on what is in the input textarea.
   * If there is an exisitng conversation, the conversation id is also sent along.
   *
   * @param inputValue - The request to send to the assistant
   */
  handleSendMessage(inputValue: string): Promise<void>;
  /**
   * Calls the AI (polling) until there is no additional requests.
   * Along the way id there is a message or context, process and show.
   * If it is solution question, start off a new request to Doc Assistant.
   *
   * @param response - stores the conversation and inquiry id
   * @param token - the authenticated user session
   * @param requestURL - AI server to request
   */
  loopRequest(response: ConversationResponse, token: string, requestURL: string): Promise<void>;
  /**
   * Request sent to the AI server via fetch.
   * ALong the way id there is a message or context, process and show.
   *
   * @param requestInfo - the request object to send to the server
   * @param token - the authenticated user session
   * @param requestURL - AI server to request
   */
  requestAIServer(requestInfo: unknown, token: string, requestURL: string): Promise<ConversationResponse>;
  /** Resets the message history and clears the chat window. */
  resetChat(): void;
  /** Emitted on demand when cards are fetched */
  readonly closeAssistant: import("@arcgis/lumina").TargetedEvent<this, boolean>;
  readonly "@eventTypes": {
    closeAssistant: ArcgisSolutionsAssistant["closeAssistant"]["detail"];
  };
}

export type ConversationResponse = {
  conversationId: string;
  inquiryId: string;
  sequenceNumber: number;
  message?: string | null;
  context?: ConversationContext;
  hasMore: boolean;
};

export type ConversationContext = {
  kind: string;
  author?: AuthorType;
  intent?: IntentType;
  results?: SuggestedSolutions[] | DocAssistantResultContext[] | unknown[];
};

export type SuggestedSolutions = {
  title: string;
  snippet: string;
  thumbnail: string;
};

export type DocAssistantResultContext = {
  reply: string;
  ref: DocAssistantResultRef[];
  followupQuestions: string[];
  status: DocAssistantResultStatus;
};

export type DocAssistantResultRef = {
  url: string;
  title: string;
  score: number;
  product: string;
  productMatch: boolean;
};

export type DocAssistantResultStatus = {
  currentStatusMessage: string;
  currentStatusStep: number;
};

export type IntentType = "Recommend solution" | "Solution question" | "Other" | "Error";

export type AuthorType = "human" | "ai" | "system";