package cn.keking.config;

import org.artofsolving.jodconverter.util.ConfigUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @author: chenjh
 * @since: 2019/4/10 17:22
 */
@Configuration
@ConfigurationProperties(prefix = "kkfile")
public class ConfigConstants {

    static {
        //pdfbox兼容低版本jdk
        System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
    }

    public static final boolean DEFAULT_CACHE_ENABLED = true;
    public static final String[] DEFAULT_TXT_TYPE = new String[]{"txt", "html", "htm", "asp", "jsp","sql", "xml",
            "json", "properties", "md", "gitignore", "log", "java","py","c","cpp","sh","bat","m","bas","prg","cmd"};
    public static final String[] DEFAULT_MEDIA_TYPE = new String[]{"mp3", "wav", "mp4", "flv"};
    public static final String DEFAULT_OFFICE_PREVIEW_TYPE = "image";
    public static final String DEFAULT_OFFICE_PREVIEW_SWITCH_DISABLED = "false";
    public static final String DEFAULT_FTP_USERNAME = null;
    public static final String DEFAULT_FTP_PASSWORD = null;
    public static final String DEFAULT_FTP_CONTROL_ENCODING = "UTF-8";
    public static final String DEFAULT_BASE_URL = "default";
    public static final String DEFAULT_FILE_DIR_VALUE = "default";
    public static final String DEFAULT_TRUST_HOST = "default";
    public static final String DEFAULT_PDF_DOWNLOAD_DISABLE = "true";
    public static final boolean DEFAULT_FILE_UPLOAD_DISABLE = false;
    public static final Set<String> TRUST_HOST_SET = new HashSet<>();

    private  Boolean cacheEnabled = DEFAULT_CACHE_ENABLED;
    private  String[] simText = DEFAULT_TXT_TYPE;
    private  String[] media = DEFAULT_MEDIA_TYPE;
    private  String[] convertMedias = {};
    private  String mediaConvertDisable;
    private  String officePreviewType;
    private  String officePreviewSwitchDisabled;
    private  String ftpUsername;
    private  String ftpPassword;
    private  String ftpControlEncoding;
    private  String baseUrl;
    private  String fileDir = ConfigUtils.getHomePath() + File.separator + "file" + File.separator;
    private  Set<String> trustHostSet = TRUST_HOST_SET;
    private  String pdfDownloadDisable = DEFAULT_PDF_DOWNLOAD_DISABLE;
    private  Boolean fileUploadDisable = DEFAULT_FILE_UPLOAD_DISABLE;
    private String officeHome;


    public  Boolean isCacheEnabled() {
        return cacheEnabled;
    }

    public void setCacheEnabled(boolean cacheEnabled) {
        this.cacheEnabled = cacheEnabled;
    }


    public  String[] getSimText() {
        return simText;
    }

    public void setSimText(String[] simText) {
        simText = simText;
    }


    public  String[] getMedia() {
        return this.media;
    }

    public void setMedia(String[] media) {
        this.media = media;
    }



    public  String[] getConvertMedias() {
        return convertMedias;
    }

    public void setConvertMedias(String[] convertMedias) {
        convertMedias = convertMedias;
    }


    public  String getMediaConvertDisable() {
        return mediaConvertDisable;
    }


    public void setMediaConvertDisable(String mediaConvertDisable) {
        this.mediaConvertDisable = mediaConvertDisable;
    }


    public  String getOfficePreviewType() {
        return officePreviewType;
    }

    public void setOfficePreviewType(String officePreviewType) {
        this.officePreviewType = officePreviewType;
    }


    public  String getFtpUsername() {
        return ftpUsername;
    }

    public void setFtpUsername(String ftpUsername) {
        this.ftpUsername = ftpUsername;
    }


    public  String getFtpPassword() {
        return ftpPassword;
    }

    public void setFtpPassword(String ftpPassword) {
        this.ftpPassword = ftpPassword;
    }


    public  String getFtpControlEncoding() {
        return ftpControlEncoding;
    }

    public void setFtpControlEncoding(String ftpControlEncoding) {
        this.ftpControlEncoding = ftpControlEncoding;
    }


    public  String getBaseUrl() {
        return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }


    public  String getFileDir() {
        return fileDir;
    }

    public void setFileDir(String fileDir) {
        if (!DEFAULT_FILE_DIR_VALUE.equalsIgnoreCase(fileDir)) {
            if (!fileDir.endsWith(File.separator)) {
                fileDir = fileDir + File.separator;
            }
            this.fileDir = fileDir;
        }
    }




    public  Set<String> getTrustHostSet() {
        return this.trustHostSet;
    }

    private  void setTrustHostSet(Set<String> trustHostSet) {
        this.trustHostSet = trustHostSet;
    }

    public  String getPdfDownloadDisable() {
        return this.pdfDownloadDisable;
    }


    public void setPdfDownloadDisable(String pdfDownloadDisable) {

        this.pdfDownloadDisable = pdfDownloadDisable;
    }



    public  String getOfficePreviewSwitchDisabled() {
        return this.officePreviewSwitchDisabled;
    }

    public void setOfficePreviewSwitchDisabled(String officePreviewSwitchDisabled) {
        this.officePreviewSwitchDisabled = officePreviewSwitchDisabled;
    }

    public  void setOfficePreviewSwitchDisabledValue(String officePreviewSwitchDisabled) {
        this.officePreviewSwitchDisabled = officePreviewSwitchDisabled;
    }

    public  Boolean getFileUploadDisable() {

        return this.fileUploadDisable;
    }

    public  void setFileUploadDisable(Boolean fileUploadDisable) {
        this.fileUploadDisable = fileUploadDisable;
    }


    public String getOfficeHome() {
        return officeHome;
    }

    public void setOfficeHome(String officeHome) {
        this.officeHome = officeHome;
    }
}
