package com.tmerclub.cloud.common.bean;


import com.tmerclub.cloud.common.constant.StorageTypeEnum;

import java.util.Objects;

/**
 * 文件上传配置
 * @author gaozijie
 * @date 2023-11-01
 */
public class UploadFile {
    /**
     * 存储类型
     * @see com.tmerclub.cloud.common.constant.StorageTypeEnum
     */
    private Integer storageType;

    /**
     * 上传终端
     */
    private String endPoint;

    /**
     * 账号
     */
    private String accessKey;

    /**
     * 密码
     */
    private String secretKey;

    /**
     * 桶名
     */
    private String bucketName;

    public UploadFile() {
    }

    public Integer getStorageType() {
        return storageType;
    }

    public void setStorageType(Integer storageType) {
        this.storageType = storageType;
    }

    public String getEndPoint() {
        return endPoint;
    }

    public void setEndPoint(String endPoint) {
        this.endPoint = endPoint;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    /**
     * 获取资源地址
     * @return 资源地址
     */
    public String getResourceUrl() {
        if (Objects.equals(this.storageType, StorageTypeEnum.MINIO.getValue())) {
            return this.endPoint + "/" + this.bucketName;
        }
        String[] endpointParam = this.endPoint.split("://");
        return endpointParam[0] + "://" + this.bucketName + "." + endpointParam[1];
    }

    @Override
    public String toString() {
        return "UploadFile{" +
                "storageType=" + storageType +
                ", endPoint='" + endPoint + '\'' +
                ", accessKey='" + accessKey + '\'' +
                ", secretKey='" + secretKey + '\'' +
                ", bucketName='" + bucketName + '\'' +
                '}';
    }
}
