package com.zhongshu.card.server.core.model.upLoadFile;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

/**
 * 获取上传令牌
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StsToken {
    //过期时间
    private Long expiredTime;
    //令牌
    private Map<String, Object> token;
    //存储对象类型
    private ObjectStorageType storageType;
    //操作文件的路径
    private Collection<String[]> paths;
    //存储桶
    private String bucket;
    //端点
    private String endPoint;

    @Schema(description = "文件url")
    private String url;

    public String getUrl() {
        String path = String.join("/", Arrays.stream(new ArrayList<>(paths).get(0)).toList());
        String url = String.format("//%s.%s.aliyuncs.com/%s", bucket, endPoint, path);
        return url;
    }
}
