package com.yunfeiyun.agmp.common.framework.web.service;

import com.yunfeiyun.agmp.common.constant.Constants;
import com.yunfeiyun.agmp.common.core.domain.model.Policy;
import com.yunfeiyun.agmp.common.framework.config.properties.OSSProperties;
import com.yunfeiyun.agmp.common.utils.spring.SpringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 策略的公共库
 *
 * @author 杨晓辉
 */
@Order(-2000)
@Component
public class PolicyService
{
    private static final Logger log = LoggerFactory.getLogger(PolicyService.class);
    @Value("${policy.upload.uploadType:localSpace}")
    private String upload;

    @Value("${policy.water:table}")
    private String water;

    @Autowired
    public OSSProperties OSSConfig;

    private Policy policy;
    /**
     * 获取policy基本信息
     */
    public Policy getPolicy()
    {
        if(policy == null) policy = new Policy();
        policy.setUpload(upload);
        policy.setWater(water);
        return policy;
    }
    /**
     * 获取policy基本信息
     */
    public static boolean enabledOssCloudPolicy()
    {
        try {
            return SpringUtils.getBean(PolicyService.class).isOssCloudPolicy();
        }catch (Exception e){
            log.error(e.getMessage());
            e.printStackTrace();
            return new PolicyService().isOssCloudPolicy();
        }
    }
    public String getUploadPolicy()
    {
        return this.upload;
    }
    public boolean isOssCloudPolicy()
    {
        return Constants.POLICY_UPLOAD_OSSCLOUD.equalsIgnoreCase(getUploadPolicy());
    }
    public OSSProperties getOSSConfig()
    {
        return this.OSSConfig;
    }
}
