package tech.easyflow.common.filestorage;

import org.junit.Test;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

import static org.junit.Assert.assertThrows;

/**
 * {@link FileStorageService} 可恢复操作默认 fail-fast 契约测试。
 */
public class FileStorageServiceTest {

    /**
     * 验证尚未实现新契约的旧后端不会伪造成功结果。
     */
    @Test
    public void recoverableDefaultsFailFast() {
        FileStorageService legacyStorage = new LegacyStorage();
        FileStorageWriteHandle handle = new FileStorageWriteHandle(
                "legacy", "", "/tmp/easyflow", "skill-content", "content.bin");

        assertThrows(UnsupportedOperationException.class,
                () -> legacyStorage.prepareRecoverableWrite("skill-content", "content.bin"));
        assertThrows(UnsupportedOperationException.class,
                () -> legacyStorage.saveRecoverable(null, handle));
        assertThrows(UnsupportedOperationException.class,
                () -> legacyStorage.deleteRecoverable(handle));
        assertThrows(UnsupportedOperationException.class,
                () -> legacyStorage.existsRecoverable(handle));
    }

    /**
     * 仅实现旧版接口的存储替身。
     */
    private static final class LegacyStorage implements FileStorageService {
        /** {@inheritDoc} */
        @Override public String save(MultipartFile file) { return ""; }
        /** {@inheritDoc} */
        @Override public void delete(String path) { }
        /** {@inheritDoc} */
        @Override public InputStream readStream(String path) throws IOException { return InputStream.nullInputStream(); }
        /** {@inheritDoc} */
        @Override public long getFileSize(String path) { return 0; }
    }
}
