import { I18nKeyOrLiteral } from "@bitwarden/common/tools/types";

import { CredentialAlgorithm, CredentialType } from "./type";

/** Credential generator metadata common across credential generators */
export type AlgorithmMetadata = {
  /** Uniquely identifies the credential configuration
   * @example
   *   // Use `isForwarderIntegration(algorithm: CredentialAlgorithm)`
   *   // to pattern test whether the credential describes a forwarder algorithm
   *   const meta : AlgorithmMetadata = // ...
   *   const { forwarder } = isForwarderIntegration(meta.id) ? credentialId : {};
   */
  id: CredentialAlgorithm;

  /** The kind of credential generated by this configuration */
  type: CredentialType;

  /** Used to order credential algorithms for display purposes.
   *  Items with lesser weights appear before entries with greater
   *  weights (i.e. ascending sort).
   */
  weight: number;

  /** Localization keys */
  // FIXME: in practice, keys like `credentialGenerated` all align
  //   with credential types and contain duplicate keys. Extract
  //   them into a "credential type metadata" type and integrate
  //   that type with the algorithm metadata instead.
  i18nKeys: {
    /** descriptive name of the algorithm */
    name: I18nKeyOrLiteral;

    /** explanatory text for the algorithm  */
    description?: I18nKeyOrLiteral;

    /** labels the generate action */
    generateCredential: I18nKeyOrLiteral;

    /** message informing users when the generator produces a new credential */
    credentialGenerated: I18nKeyOrLiteral;

    /* labels the action that assigns a generated value to a domain object */
    useCredential: I18nKeyOrLiteral;

    /** labels the generated output */
    credentialType: I18nKeyOrLiteral;

    /** labels the copy output action */
    copyCredential: I18nKeyOrLiteral;
  };

  /** fine-tunings for generator user experiences */
  capabilities: {
    /** `true` when the generator supports autogeneration
     *  @remarks this property is useful when credential generation
     *   carries side effects, such as configuring a service external
     *   to Bitwarden.
     */
    autogenerate: boolean;

    /** Well-known fields to display on the options panel or collect from the environment.
     *  @remarks: at present, this is only used by forwarders
     */
    fields: string[];
  };
};
