package org.raddatz.familienarchiv.importing;

import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Test seam for opening a {@link File} as an {@link InputStream}. Extracted so the magic-byte
 * check in {@link DocumentImporter} can be unit-tested for the IO-error branch by injecting a
 * mock that throws, without needing a Mockito spy on the importer itself.
 *
 * <p>Production uses {@link DefaultFileStreamOpener}, a one-line delegate to
 * {@code new FileInputStream(file)}.
 */
@FunctionalInterface
public interface FileStreamOpener {

    /** Opens {@code file} for sequential reads. Caller closes the returned stream. */
    InputStream open(File file) throws IOException;

    /** Default production implementation: plain {@code FileInputStream}. */
    @Component
    final class DefaultFileStreamOpener implements FileStreamOpener {

        @Override
        public InputStream open(File file) throws IOException {
            return new FileInputStream(file);
        }
    }
}
