package com.njcn.gather.aireport.common.config;

import cn.hutool.core.util.StrUtil;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * ai-report MinIO 配置。
 */
@Data
@Component
@ConfigurationProperties(prefix = "storage.minio")
public class AiReportMinioProperties {

    private String endpoint;

    private String accessKey;

    private String secretKey;

    private Map<String, String> buckets = new LinkedHashMap<String, String>();

    public String requireBucket(String bucketKey) {
        String bucketName = buckets.get(bucketKey);
        if (StrUtil.isBlank(bucketName)) {
            throw new BusinessException(CommonResponseEnum.FAIL, "MinIO桶配置缺失：" + bucketKey);
        }
        return bucketName;
    }
}
