package com.airlock.iam.admin.application.configuration.airlock2fa;

import com.airlock.iam.core.misc.util.report.ReportRenderer;
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.FileProperty;
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;
import java.io.File;
import java.util.Optional;

@Plugin(
   displayName = "Create Airlock 2FA Hardware Token Shipment Letters",
   description = "Settings for user's hardware token shipment letters. Such a letter is designed to accompany the shipment of the hardware token to the user and contains information relevant to its first use."
)
@PluginLicenseRestriction(moduleAffiliation = "Airlock2FA")
public final class Airlock2FAShipmentLettersConfig {
   @PluginProperty(
      description = "Defines how shipment letters (e.g. PDFs) are rendered.<p>The following placeholders can be used in the templates<ul><li><code>${<i>User Context Data Name</i>}</code> - context data of the user.</li><li><code>${deviceManufacturer}</code> - manufacturer of device.</li><li><code>${deviceModel}</code> - model of device.</li><li><code>${deviceSerialNumber}</code> - serial number of device.</li><li><code>${deviceActivationCode}</code> - activation code of device, if any.</li></ul></p>",
      optional = false
   )
   private ReportRenderer renderer;
   @FileProperty(
      displayName = "Working Directory",
      description = "A writable directory used to store a partially rendered shipment letter.<br/>If this property is defined, shipment letters are not directly generated into the output directory (see other property) but they are generated into this working directory and are then moved into the output directory once they are done.<br/>This helps to solve problems with processes that automatically read the rendered letters and therefore might not see the fully rendered result. Make sure that the working directory and the output directory reside in the same file system (otherwise the moving of the generated file will not be atomic).<br/>The directory is either absolute or relative to the JVMs current directory.",
      optional = true,
      isDirectory = true,
      assureWritable = true,
      assureExistence = true,
      exampleValues = {"tmp", "under-construction", "working"}
   )
   private File workingDirectory;
   @FileProperty(
      displayName = "Output Directory",
      description = "The directory where the printable letters will be stored.",
      optional = false,
      exampleValues = {"/var/airlock/letters", "./pdfs"},
      assureExistence = true
   )
   private File outputDirectory;
   @StringProperty(
      displayName = "Language Context Data Name",
      description = "The user's context data attribute containing its language. The language is used to choose the template in the renderer. If left empty, the default template will be used.",
      optional = true,
      suggestedValues = "language"
   )
   private String languageContextDataName;

   public ReportRenderer getRenderer() {
      return this.renderer;
   }

   public Optional<File> getWorkingDirectory() {
      return Optional.ofNullable(this.workingDirectory);
   }

   public File getOutputDirectory() {
      return this.outputDirectory;
   }

   public Optional<String> getLanguageContextDataName() {
      return Optional.ofNullable(this.languageContextDataName);
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public Airlock2FAShipmentLettersConfig(ReportRenderer renderer, File workingDirectory, File outputDirectory, String languageContextDataName) {
      this.renderer = renderer;
      this.workingDirectory = workingDirectory;
      this.outputDirectory = outputDirectory;
      this.languageContextDataName = languageContextDataName;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class Airlock2FAShipmentLettersConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private ReportRenderer renderer;
      @SuppressFBWarnings(justification = "generated code")
      private File workingDirectory;
      @SuppressFBWarnings(justification = "generated code")
      private File outputDirectory;
      @SuppressFBWarnings(justification = "generated code")
      private String languageContextDataName;

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

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAShipmentLettersConfig.Airlock2FAShipmentLettersConfigBuilder renderer(ReportRenderer renderer) {
         this.renderer = renderer;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAShipmentLettersConfig.Airlock2FAShipmentLettersConfigBuilder workingDirectory(File workingDirectory) {
         this.workingDirectory = workingDirectory;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAShipmentLettersConfig.Airlock2FAShipmentLettersConfigBuilder outputDirectory(File outputDirectory) {
         this.outputDirectory = outputDirectory;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAShipmentLettersConfig.Airlock2FAShipmentLettersConfigBuilder languageContextDataName(String languageContextDataName) {
         this.languageContextDataName = languageContextDataName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAShipmentLettersConfig build() {
         return new Airlock2FAShipmentLettersConfig(this.renderer, this.workingDirectory, this.outputDirectory, this.languageContextDataName);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "Airlock2FAShipmentLettersConfig.Airlock2FAShipmentLettersConfigBuilder(renderer="
            + this.renderer
            + ", workingDirectory="
            + this.workingDirectory
            + ", outputDirectory="
            + this.outputDirectory
            + ", languageContextDataName="
            + this.languageContextDataName
            + ")";
      }
   }
}
