/**
 * @mergeTarget
 * @module Src/Messages/Types
 */

import {
  LisioCategoryNames,
  LisioParameterNames,
  LisioProfileNames,
} from "@lisio/lisio-profils";
import { TranslationLanguages } from "../controllers/translation/translation-controller";

/**
 * Type for message handler functions
 * @param {string} datas - Datas sent by client script
 * @returns Returns a promise containing nothing
 */
type MessageHandler = (datas: string) => Promise<void>;

/**
 * Datas needed by the widget to be initialized
 */
type InitMessageDatas = {
  /**
   * Language in which the widget will be translated
   */
  widgetLang: TranslationLanguages;
  /**
   * Origin of the client script
   */
  origin: string;

  /**
   * Complete url of the client script
   */
  url: string;

  /**
   * Widget version in number :
   *  * 1 : essential
   *  * 2 : complete
   *  * 3 : first
   *  * 4 : welcome
   */
  widgetVersion: number;
  /**
   * Translation mode
   *  * google_translation
   *  * deepl_translation
   *  * undefined
   */
  translationMode?:
    | LisioCategoryNames.GOOGLE_TRANSLATION
    | LisioCategoryNames.DEEPL_TRANSLATION
    | "none";

  /**
   * Priorized languages
   */
  priorizedLanguages: string[];

  /**
   * List of categories to hide
   */
  categoriesToHide?: LisioCategoryNames[];
  /**
   * List of categories to hide
   */
  profilesToHide?: LisioProfileNames[];
  /**
   * List of parameters to hide
   */
  parametersToHide?: LisioParameterNames[];

  /**
   * Indicates if client pay for carbon compensation
   */
  compensation: boolean;

  /**
   * Indicates if group need to be reorderer in a specific way
   * @property {number} groupId - Id of the group of category or profile
   */
  groupsOrder?: {
    groupId: number;
    position: number;
  }[];
  /**
   * URL of the api for statistics
   */
  statisticsAPIURL: string;
  /**
   * List of queries in url from book page
   */
  bookPageUrlQueries: string[];
  /**
   * Indicates page to directly go to instead of home page
   */
  shortcutTo: string;

  /**
   * Indicates origin of event page to directly go to instead of home page
   */
  eventShortcutTo?: number;
  /**
   * Indicates if previous page of client script was book page
   */
  isReferrerBookPage: boolean;
  /**
   * Colors of widget theme
   */
  colors: {
    primary: string;
    eco: string;
  };
  originDomain: string;
  /**
   * Custom image to display in header
   */
  topBarImg?: string;
  /**
   * Popin used on client website
   */
  popinUsed: string;
};

/**
 * Datas needed by the deepl transaltion api
 */
type TranslatorAPIDatas = {
  /**
   * Body of the request to transmit
   */
  body: {
    /**
     * Array of texts to translate
     */
    originalTexts: string[];
    /**
     * Language of texts
     */
    originLangISO: string;
    /**
     * Language in which texts will be translated
     */
    translateLangISO: string;
    /**
     * Date in milliseconds when request was sent
     */
    epochSent: number;
  };
  /**
   * Identifier of the client script request
   */
  keyHandler: string;
};

/**
 * Datas returned by the deepl transaltion api
 */
type TranslatorAPIResponsesDatas = {
  /**
   * Original text object, representing a piece of SQL table "origin_texts"
   */
  originTextDTO: {
    /**
     * Original language object, representing a piece of SQL table "languages"
     */
    originLangDTO: {
      /**
       * ISO code of language
       */
      languageISO: string;
    };
    /**
     * Original text
     */
    originText: string;
  };
  /**
   * Translation language object, representing a piece of SQL table "languages"
   */
  translateLangDTO: {
    /**
     * ISO code of language
     */
    languageISO: string;
  };
  /**
   * Transalted text
   */
  translatedText: string;
}[];

export type {
  InitMessageDatas,
  MessageHandler,
  TranslatorAPIDatas,
  TranslatorAPIResponsesDatas,
};
