package com.philisense.www.factory;

import com.philisense.www.cloud.*;
import com.philisense.www.config.OssStorageProperties;
import com.philisense.www.enums.OssTypeEnum;
import com.philisense.www.utils.AssertUtils;
import com.philisense.www.utils.SpringContextUtils;

/**
 * 文件上传Factory
 *
 */
public final class OssStorageFactory {
    private static OssStorageProperties config;

    static {
        config = SpringContextUtils.getBean(OssStorageProperties.class);
    }

    public static OssStorageService build() {
        OssStorageService ossStorageService;
        switch (config.getOssType()) {
            case ALIYUN:
                AssertUtils.isNull(config.getAliyun(), String.format("请先配置%sOOS参数", OssTypeEnum.ALIYUN.getName()));
                ossStorageService = new AliyunStorageService(config.getAliyun(), config.getDiskName());
                break;
            case QINIU:
                AssertUtils.isNull(config.getQiniu(), String.format("请先配置%sOOS参数", OssTypeEnum.QINIU.getName()));
                ossStorageService = new QiniuStorageService(config.getQiniu(), config.getDiskName());
                break;
            case UPYUN:
                AssertUtils.isNull(config.getUpyun(), String.format("请先配置%sOOS参数", OssTypeEnum.UPYUN.getName()));
                ossStorageService = new UpyunStorageService(config.getUpyun(), config.getDiskName());
                break;
            case MINIO:
                AssertUtils.isNull(config.getMinio(), String.format("请先配置%sOOS参数", OssTypeEnum.MINIO.getName()));
                ossStorageService = new MinioStorageService(config.getMinio(), config.getDiskName());
                break;
            case GOFASTDFS:
                AssertUtils.isNull(config.getGoFastDFS(), String.format("请先配置%sOOS参数", OssTypeEnum.GOFASTDFS.getName()));
                ossStorageService = new GoFastDFSStorageService(config.getGoFastDFS(), config.getDiskName());
                break;
            default:
                AssertUtils.isNull(config.getLocal(), String.format("请先配置%sOOS参数", OssTypeEnum.LOCAL.getName()));
                ossStorageService = new LocalStorageService(config.getLocal(), config.getDiskName());
        }

        return ossStorageService;
    }


}
