package cz.moneta.test.harness.connectors;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class DemoConnector implements Connector {

    private Path directory;

    public void connectToTempDirectoryService(String name) {
        try {
            directory = Files.createTempDirectory(name);
        } catch (IOException e) {
            throw new RuntimeException("Cannot connect to temp filesystem service", e);
        }
    }

    public void createFile(String name) {
        try {
            Files.createFile(directory.resolve(name));
        } catch (IOException e) {
            throw new RuntimeException(String.format("Cannot create file: %s", name), e);
        }
    }

    public boolean fileExists(String name) {
        return Files.exists(directory.resolve(name));
    }

    public void deleteFile(String name) {
        try {
            Files.delete(directory.resolve(name));
        } catch (IOException e) {
            throw new RuntimeException(String.format("Cannot delete file: %s", name), e);
        }
    }

}
