package org.shop.crop.service;

import org.shop.crop.config.MediaProperties;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
public class MediaContext {

    private final File tempMergeFileDir;

    public MediaContext(MediaProperties mediaProperties) {
        this.tempMergeFileDir = createTempDir(mediaProperties.getTempDir());
    }

    private File createTempDir(String path) {
        File dir = new File(path);
        if (!dir.exists()) {
            boolean created = dir.mkdirs();
            if (!created) {
                throw new RuntimeException("无法创建临时目录: " + path);
            }
            System.out.println("✅ 已创建临时目录: " + path);
        }
        return dir;
    }

    public File getTempMergeFileDir() {
        return tempMergeFileDir;
    }
}

