package de.tu_dresden.lat.proofs.json;

import java.io.File;
import java.io.IOException;

import com.fasterxml.jackson.databind.ObjectMapper;

import de.tu_dresden.lat.proofs.data.ParsingException;
import de.tu_dresden.lat.proofs.interfaces.IProof;
import de.tu_dresden.lat.proofs.interfaces.IProofParser;

public class JsonProofParser implements IProofParser {

	private static class LazyHolder {
		static JsonProofParser instance = new JsonProofParser();
	}

	public static JsonProofParser getInstance() {
		return LazyHolder.instance;
	}

	@Override
	public IProof fromFile(File file) {
		ObjectMapper mapper = new ObjectMapper();

		try {
			return mapper.readValue(file, IProof.class);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	@Override
	public IProof parseProof(String string) throws ParsingException {

		ObjectMapper mapper = new ObjectMapper();

		try {
			return mapper.readValue(string, IProof.class);
		} catch (IOException e) {
			throw new ParsingException(e);
		}
	}

}
