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

import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.EnumProperty;
import com.airlock.iam.plugin.api.annotation.property.StringListProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.List;

@Plugin(
   displayName = "CSV Users Export",
   description = "Specifies what data to include in the export. A download button is included on the user list page. When pressed the current selection (filter) of users are downloaded as a CSV file.<p>For efficiency reasons, prefer using a \"User Store Configuration\" over a \"User Persister Configuration\".</p>"
)
public class CsvUsersExportConfig implements UsersExportConfig {
   @EnumProperty(
      description = "Valid values of this property are: <ul> <li><b>BASIC</b>: The downloaded file contains only basic infos about the user (username, roles) plus the context data selected by the context keys.</li><li><b>FULL</b>: The downloaded file contains all available data about the user plus the context data.</li></ul>",
      optional = true,
      defaultValue = "BASIC"
   )
   private CsvUsersExportConfig.DownloadType type;
   @StringListProperty(
      description = "This property specifies a list of keys of the context data values to be included in the user data download file. Only values are included that the admin user is allowed to see (according to authorization settings).",
      exampleElements = {"surname", "givenname"},
      optional = true
   )
   private List<String> contextKeys;
   @StringProperty(
      description = "Defines the character set to use when exporting the user list as CSV file.",
      allowedValues = {"UTF-8", "ISO-8859-1", "UTF-16", "UTF-16BE", "UTF-16LE", "US-ASCII", "ISO-8859-15"},
      optional = true,
      defaultValue = "UTF-8"
   )
   private String charset;
   @StringProperty(
      description = "This property specifies the separation character used in the generated CSV file in order to separate fields from eachother. Usually, a comma is used but, e.g., Excel requires this to be a semicolon. To use the generated file with Excel, use a semicolon, to use it with most programs, use a comma. The separator character MAY be surrounded by double quotes. E.g., the space character is specified as \" \".",
      optional = true,
      defaultValue = ";",
      suggestedValues = {",", ";", ":", "|"}
   )
   private String separationCharacter;

   public CsvUsersExportConfig.DownloadType getType() {
      return this.type;
   }

   public List<String> getContextKeys() {
      return this.contextKeys;
   }

   public String getCharset() {
      return this.charset;
   }

   public String getSeparationCharacter() {
      return this.separationCharacter;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public CsvUsersExportConfig(CsvUsersExportConfig.DownloadType type, List<String> contextKeys, String charset, String separationCharacter) {
      this.type = type;
      this.contextKeys = contextKeys;
      this.charset = charset;
      this.separationCharacter = separationCharacter;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class CsvUsersExportConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private CsvUsersExportConfig.DownloadType type;
      @SuppressFBWarnings(justification = "generated code")
      private List<String> contextKeys;
      @SuppressFBWarnings(justification = "generated code")
      private String charset;
      @SuppressFBWarnings(justification = "generated code")
      private String separationCharacter;

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

      @SuppressFBWarnings(justification = "generated code")
      public CsvUsersExportConfig.CsvUsersExportConfigBuilder type(CsvUsersExportConfig.DownloadType type) {
         this.type = type;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CsvUsersExportConfig.CsvUsersExportConfigBuilder contextKeys(List<String> contextKeys) {
         this.contextKeys = contextKeys;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CsvUsersExportConfig.CsvUsersExportConfigBuilder charset(String charset) {
         this.charset = charset;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CsvUsersExportConfig.CsvUsersExportConfigBuilder separationCharacter(String separationCharacter) {
         this.separationCharacter = separationCharacter;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CsvUsersExportConfig build() {
         return new CsvUsersExportConfig(this.type, this.contextKeys, this.charset, this.separationCharacter);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "CsvUsersExportConfig.CsvUsersExportConfigBuilder(type="
            + this.type
            + ", contextKeys="
            + this.contextKeys
            + ", charset="
            + this.charset
            + ", separationCharacter="
            + this.separationCharacter
            + ")";
      }
   }

   public enum DownloadType {
      BASIC,
      FULL;
   }
}
