package com.airlock.iam.transactionapproval.application.configuration.cronto;

import com.airlock.iam.common.api.application.configuration.cronto.CrontoMessageProviderConfig;
import com.airlock.iam.core.misc.cronto.CrontoHandler;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.license.PluginLicenseRestriction;
import com.airlock.iam.plugin.api.annotation.property.PluginProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "This message provider creates a customizable transaction approval message for Cronto using the Parameters received in the Transaction Approval Parameter Step. The message template is identified by the message translation key and may contain variables that will be replaced with parameters from the Parameter Step.",
   displayName = "Transaction Approval Cronto Message Provider"
)
@PluginLicenseRestriction(moduleAffiliation = "TransactionApproval")
public class CrontoMessageProviderImplConfig implements CrontoMessageProviderConfig {
   @StringProperty(
      description = "This key identifies the message template that is used to generate the message. It can contain variables, e.g. 'cronto.${type}.message'. Variables are replaced with the corresponding values sent in the Transaction Approval Parameter Step. This allows using different message templates for different transaction types. For more information about formatting, consult the description in the strings_*.properties located at instances/common/transaction-approval-texts.",
      exampleValues = "cronto.payment.message",
      optional = false
   )
   private String messageTranslationKey;
   @StringProperty(
      description = "Resource key to select the localized template to display the push title. The localized template can contain variables (e.g. <tt>${town}</tt>).",
      defaultValue = "cronto.push.transaction-signing.title",
      optional = true
   )
   private String pushTitleResourceKey;
   @StringProperty(
      description = "Resource key to select the localized template to display the push subject. The localized template can contain variables (e.g. <tt>${town}</tt>).",
      defaultValue = "cronto.push.transaction-signing.subject",
      optional = true
   )
   private String pushSubjectResourceKey;
   @PluginProperty(
      description = "The Cronto handler used to generate the message. This needs to be the same handler as in the Cronto Step where this Message Provider is used in.",
      globalPluginReference = "globalCrontoSettings",
      optional = false
   )
   private CrontoHandler crontoHandler;
   @StringProperty(
      description = "This key identifies the translation of the amount label (see message provider description). ",
      defaultValue = "cronto.amountLabel",
      optional = true
   )
   private String amountLabelKey;
   @StringProperty(
      description = "This parameter name identifies the variable form the Transaction Approval Parameter Step that represents the amount. If left empty, no amount is set in the transaction details.",
      optional = true
   )
   private String amountParameterName;
   @StringProperty(
      description = "This parameter name identifies the variable form the Transaction Approval Parameter Step that represents the currency. If left empty, no currency is set in the transaction details.",
      optional = true
   )
   private String currencyParameterName;

   public String getMessageTranslationKey() {
      return this.messageTranslationKey;
   }

   public String getPushTitleResourceKey() {
      return this.pushTitleResourceKey;
   }

   public String getPushSubjectResourceKey() {
      return this.pushSubjectResourceKey;
   }

   public CrontoHandler getCrontoHandler() {
      return this.crontoHandler;
   }

   public String getAmountLabelKey() {
      return this.amountLabelKey;
   }

   public String getAmountParameterName() {
      return this.amountParameterName;
   }

   public String getCurrencyParameterName() {
      return this.currencyParameterName;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder builder() {
      return new CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder();
   }

   @SuppressFBWarnings(justification = "generated code")
   public CrontoMessageProviderImplConfig() {
   }

   @SuppressFBWarnings(justification = "generated code")
   public CrontoMessageProviderImplConfig(
      String messageTranslationKey,
      String pushTitleResourceKey,
      String pushSubjectResourceKey,
      CrontoHandler crontoHandler,
      String amountLabelKey,
      String amountParameterName,
      String currencyParameterName
   ) {
      this.messageTranslationKey = messageTranslationKey;
      this.pushTitleResourceKey = pushTitleResourceKey;
      this.pushSubjectResourceKey = pushSubjectResourceKey;
      this.crontoHandler = crontoHandler;
      this.amountLabelKey = amountLabelKey;
      this.amountParameterName = amountParameterName;
      this.currencyParameterName = currencyParameterName;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class CrontoMessageProviderImplConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String messageTranslationKey;
      @SuppressFBWarnings(justification = "generated code")
      private String pushTitleResourceKey;
      @SuppressFBWarnings(justification = "generated code")
      private String pushSubjectResourceKey;
      @SuppressFBWarnings(justification = "generated code")
      private CrontoHandler crontoHandler;
      @SuppressFBWarnings(justification = "generated code")
      private String amountLabelKey;
      @SuppressFBWarnings(justification = "generated code")
      private String amountParameterName;
      @SuppressFBWarnings(justification = "generated code")
      private String currencyParameterName;

      @SuppressFBWarnings(justification = "generated code")
      CrontoMessageProviderImplConfigBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder messageTranslationKey(String messageTranslationKey) {
         this.messageTranslationKey = messageTranslationKey;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder pushTitleResourceKey(String pushTitleResourceKey) {
         this.pushTitleResourceKey = pushTitleResourceKey;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder pushSubjectResourceKey(String pushSubjectResourceKey) {
         this.pushSubjectResourceKey = pushSubjectResourceKey;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder crontoHandler(CrontoHandler crontoHandler) {
         this.crontoHandler = crontoHandler;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder amountLabelKey(String amountLabelKey) {
         this.amountLabelKey = amountLabelKey;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder amountParameterName(String amountParameterName) {
         this.amountParameterName = amountParameterName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder currencyParameterName(String currencyParameterName) {
         this.currencyParameterName = currencyParameterName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CrontoMessageProviderImplConfig build() {
         return new CrontoMessageProviderImplConfig(
            this.messageTranslationKey,
            this.pushTitleResourceKey,
            this.pushSubjectResourceKey,
            this.crontoHandler,
            this.amountLabelKey,
            this.amountParameterName,
            this.currencyParameterName
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "CrontoMessageProviderImplConfig.CrontoMessageProviderImplConfigBuilder(messageTranslationKey="
            + this.messageTranslationKey
            + ", pushTitleResourceKey="
            + this.pushTitleResourceKey
            + ", pushSubjectResourceKey="
            + this.pushSubjectResourceKey
            + ", crontoHandler="
            + this.crontoHandler
            + ", amountLabelKey="
            + this.amountLabelKey
            + ", amountParameterName="
            + this.amountParameterName
            + ", currencyParameterName="
            + this.currencyParameterName
            + ")";
      }
   }
}
