package com.cm.common.config.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @ClassName: FileConfig
 * @Description: 文件配置
 * @Author: wenc
 * @Date: 2019/1/3 3:12 PM
 * @Version: 1.0
 **/
@Component
@ConfigurationProperties(prefix = "file")
public class FileProperties {

    private String uploadPath;
    private String imageTypes;
    private String videoTypes;
    private String audioTypes;
    private String fileTypes;
    private Integer maxFileCount;
    private Double imageOutputQuality;
    private FileMediaMaxDurationProperties mediaMaxDuration;

    public String getUploadPath() {
        return uploadPath;
    }

    public void setUploadPath(String uploadPath) {
        this.uploadPath = uploadPath;
    }

    public String getImageTypes() {
        return imageTypes == null ? null : imageTypes.trim();
    }

    public void setImageTypes(String imageTypes) {
        this.imageTypes = imageTypes;
    }

    public String getVideoTypes() {
        return videoTypes == null ? null : videoTypes.replaceAll("\\s", "");
    }

    public void setVideoTypes(String videoTypes) {
        this.videoTypes = videoTypes;
    }

    public String getAudioTypes() {
        return audioTypes == null ? null : audioTypes.replaceAll("\\s", "");
    }

    public void setAudioTypes(String audioTypes) {
        this.audioTypes = audioTypes;
    }

    public String getFileTypes() {
        return fileTypes == null ? null : fileTypes.replaceAll("\\s", "");
    }

    public void setFileTypes(String fileTypes) {
        this.fileTypes = fileTypes;
    }

    public Integer getMaxFileCount() {
        return maxFileCount == null ? 1 : maxFileCount;
    }

    public void setMaxFileCount(Integer maxFileCount) {
        this.maxFileCount = maxFileCount;
    }

    public Double getImageOutputQuality() {
        return imageOutputQuality == null ? 0.4 : imageOutputQuality;
    }

    public void setImageOutputQuality(Double imageOutputQuality) {
        this.imageOutputQuality = imageOutputQuality;
    }

    public FileMediaMaxDurationProperties getMediaMaxDuration() {
        return mediaMaxDuration;
    }

    public void setMediaMaxDuration(FileMediaMaxDurationProperties mediaMaxDuration) {
        this.mediaMaxDuration = mediaMaxDuration;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"uploadPath\":\"")
                .append(uploadPath).append('\"');
        sb.append(",\"imageTypes\":\"")
                .append(imageTypes).append('\"');
        sb.append(",\"videoTypes\":\"")
                .append(videoTypes).append('\"');
        sb.append(",\"audioTypes\":\"")
                .append(audioTypes).append('\"');
        sb.append(",\"fileTypes\":\"")
                .append(fileTypes).append('\"');
        sb.append(",\"maxFileCount\":")
                .append(maxFileCount);
        sb.append(",\"imageOutputQuality\":")
                .append(imageOutputQuality);
        sb.append(",\"mediaMaxDuration\":")
                .append(mediaMaxDuration);
        sb.append('}');
        return sb.toString();
    }
}
