package com.loan.system.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.beans.factory.annotation.Value; // 添加此行

import java.util.Arrays;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;

@Configuration
public class FileUploadConfig {

    @Value("${upload.location}")
    private String uploadDir;

    @Value("${upload.extensions}")
    private String allowedExtensions;

    public String getUploadDir() {
        return uploadDir.endsWith("/")? uploadDir : uploadDir + "/";
    }

    /** 把 yml 中的扩展名字符串解析成 Set<String> */
    public Set<String> getAllowedExtensions() {
        return Arrays.stream(allowedExtensions.split(","))
                .map(s -> s.toLowerCase(Locale.ROOT).trim())
                .collect(Collectors.toSet());
    }
}
