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 */
  category: 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 */
  i18nKeys: {
    /** descriptive name of the algorithm */
    name: string;

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

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

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

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

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

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

  /** 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[];
  };
};
