package cn.com.qmth.stmms.ms.commons.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.UUID;

/**
 * 系统配置
 * Created by zhengmin on 2016/11/18.
 */
@Component
@ConfigurationProperties(prefix = "sys.config")
public class SystemConfig {

    @Autowired
    private ImageServerConfig imageServerConfig;

    /**
     * 裁切原图目录
     */
    private String imageDir;

    /**
     * 缩略图目录
     */
    private String thumbDir;

    /**
     * 原图目录
     */
    private String sheetDir;

    /**
     * 分数水印目录
     */
    private String watermark;

    /**
     * 本地文件保存路径
     */
    private String localhostPath;

    private String path = "/api/file/image/download/";

    public String getWatermark() {
        return watermark;
    }

    public void setWatermark(String watermark) {
        this.watermark = watermark;
    }

    public String getImageDir() {
        return imageDir;
    }

    public void setImageDir(String imageDir) {
        this.imageDir = imageDir;
    }

    public String getThumbDir() {
        return thumbDir;
    }

    public void setThumbDir(String thumbDir) {
        this.thumbDir = thumbDir;
    }

    public String getLocalhostPath() {
        return localhostPath;
    }

    public void setLocalhostPath(String localhostPath) {
        this.localhostPath = localhostPath;
    }

    public String getLocalhostPathUrl() {
        return imageServerConfig.getImageServer();
    }

    public String getFilesUrl() {
        return imageServerConfig.getBaseServer();
    }

    public String getThumbUrl(Long workId, String subject, String areaCode, String examNumber) {
        return imageServerConfig.getImageServer() + "/thumbs/" + String.valueOf(workId) + "/"
                + subject + "/" + areaCode + "/" + examNumber + ".jpg?random=" + UUID.randomUUID().toString();
    }

    public String getImageUrl(Long workId, String subject, String areaCode, String examNumber) {
        return imageServerConfig.getImageServer() + "/images/" + String.valueOf(workId) + "/"
                + subject + "/" + areaCode + "/" + examNumber + ".jpg?random=" + UUID.randomUUID().toString();
    }

    public String getSheetUrl(Long workId, String subject, String areaCode, String examNumber) {
        return imageServerConfig.getImageServer() + "/sheet/" + String.valueOf(workId) + "/"
                + subject + "/" + areaCode + "/" + examNumber + ".jpg?random=" + UUID.randomUUID().toString();
    }

    public String getWaterMarkUrl(Long workId, String subject, String areaCode, String examNumber) {
        return imageServerConfig.getImageServer() + "/watermark/" + String.valueOf(workId) + "/"
                + subject + "/" + areaCode + "/" + examNumber + ".jpg?random=" + UUID.randomUUID().toString();
    }

    public String getThumbUrl(Long workId, Integer subjectId, Long studentId, Integer imageType) {
        return imageServerConfig.getBaseServer() + path + workId + "/"
                + subjectId + "/" + studentId + "/" + imageType + "?random=" + UUID.randomUUID().toString();
    }

    public String getImageUrl(Long workId, Integer subjectId, Long studentId, Integer imageType) {
        return imageServerConfig.getBaseServer() + path + workId + "/"
                + subjectId + "/" + studentId + "/" + imageType + "?random=" + UUID.randomUUID().toString();
    }

    public String getSheetUrl(Long workId, Integer subjectId, Long studentId, Integer imageType) {
        return imageServerConfig.getBaseServer() + path + workId + "/"
                + subjectId + "/" + studentId + "/" + imageType + "?random=" + UUID.randomUUID().toString();
    }

    public String getWaterMarkUrl(Long workId, Integer subjectId, Long studentId, Integer imageType) {
        return imageServerConfig.getBaseServer() + path + workId + "/"
                + subjectId + "/" + studentId + "/" + imageType + "?random=" + UUID.randomUUID().toString();
    }

    public String getSheetDir() {
        return sheetDir;
    }

    public void setSheetDir(String sheetDir) {
        this.sheetDir = sheetDir;
    }

}
