package com.ycwl.basic.storage.entity;

import cn.hutool.crypto.digest.MD5;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class AliOssStorageConfig extends StorageConfig {
    private String endpoint;
    private String accessKeyId;
    private String accessKeySecret;
    private String bucketName;
    private String url;
    private String region;
    private String prefix;

    @Override
    public void checkEverythingOK() {
        // TODO: 检查配置是否正确
    }

    @Override
    public String identity() {
        return MD5.create().digestHex16(accessKeyId + bucketName + prefix);
    }

    public String getUrl() {
        String url = this.url;
        if (url == null) {
            url = bucketName + "." + endpoint;
        }
        if (!url.startsWith("http")) {
            url = "https://" + url;
        }
        if (url.endsWith("/")) {
            url = url.substring(0, url.length() - 1);
        }
        return url;
    }
}
