package lc.mecha.io;

import java.io.IOException;
import java.nio.file.Path;
import java.util.UUID;

public class Persister {
    private final Path basePath;

    public Persister(Path basePath) {
        this.basePath = basePath;
        //noinspection ResultOfMethodCallIgnored
        basePath.toFile().mkdirs();
    }

    public Path getBasePath() {
        return basePath;
    }

    public OutputFile output(Path filename) throws IOException {
        UUID id = UUID.randomUUID();
        Path tmpFile = basePath.resolve(id + ".tmp");
        return new OutputFile(basePath.resolve(filename), tmpFile);
    }
}
