package com.dxhy.oss.config;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.jcraft.jsch.ChannelSftp;

import lombok.Data;

/**
 * @author jiaohongyang
 */
@Component
@Data
public class OssConfig {

    /**
     * oss 服务类型 JD AL FTP
     */
    @Value("${oss.ossType:FTP}")
    public String ossType;
    /**
     * 阿里请求地址
     */
    @Value("${oss.endpointUrl:}")
    public String endpointUrl;
    /**
     * 访问密钥
     */
    @Value("${oss.accessKeyId:}")
    public String accessKeyId;
    /**
     * 访问密钥
     */
    @Value("${oss.accessKeySecret:}")
    public String accessKeySecret;

    /**
     * 京东云地域
     */
    @Value("${oss.region:}")
    public String region;
    /**
     * 实例
     */
    @Value("${oss.bucketName:}")
    public String bucketName;

    /**
     * ftp上传的根路径
     */
    @Value("${ftp.connection.pathPrefix:}")
    public String pathPrefix;

    /**
     * ftp服务器地址
     */
    @Value("${ftp.connection.hostname:}")
    public String hostname;

    /**
     * ftp服务器端口
     */
    @Value("${ftp.connection.port:62236}")
    public String port;

    /**
     * ftp登录密码
     */
    @Value("${ftp.connection.password:}")
    public String password;

    @Value("${ftp.connection.timeout:6000}")
    public String timeout;
    /**
     * ftp登录账号
     */
    @Value("${ftp.connection.username:}")
    public String username;

    @Value("${ftp.connection.localPathDefault:}")
    public String localPathDefault;

    /**
     * 临时路径
     */
    @Value("${ftp.connection.tempPath:}")
    public String tempPath;

    /**
     * ftp配置信息
     */
    @Value("${ftp.connection.size:2}")
    public String pdfSize;

    /**
     * 图片的最大大小
     */
    @Value("${oss.imageSize:10485760}")
    public long imageSize;

    /**
     * 其他文件的最大大小
     */
    @Value("${oss.fileSize:1073741824}")
    public long fileSize;

    private Pool pool = new Pool();

    public static class Pool extends GenericObjectPoolConfig<ChannelSftp> {

        private int maxTotal = DEFAULT_MAX_TOTAL;

        private int maxIdle = DEFAULT_MAX_IDLE;

        private int minIdle = DEFAULT_MIN_IDLE;

        public Pool() {
            super();
        }

        @Override
        public int getMaxTotal() {
            return maxTotal;
        }

        @Override
        public void setMaxTotal(int maxTotal) {
            this.maxTotal = maxTotal;
        }

        @Override
        public int getMaxIdle() {
            return maxIdle;
        }

        @Override
        public void setMaxIdle(int maxIdle) {
            this.maxIdle = maxIdle;
        }

        @Override
        public int getMinIdle() {
            return minIdle;
        }

        @Override
        public void setMinIdle(int minIdle) {
            this.minIdle = minIdle;
        }

    }
}
