package xyz.wbsite.dbtool.javafx.manger;

import xyz.wbsite.dbtool.javafx.po.Project;
import xyz.wbsite.dbtool.web.frame.utils.FileUtil;
import xyz.wbsite.dbtool.web.frame.utils.MapperUtil;

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

public class JsonManager {

    public Project inflate(String json) {
        Project project = MapperUtil.toJava(json, Project.class);
        return project;
    }

    public Project inflate(File json) {
        try {
            return inflate(FileUtil.readFileToString(json));
        } catch (IOException e) {
            e.printStackTrace();
            return new Project();
        }
    }

    public boolean saveAs(File file, Project project) {
        String data = MapperUtil.toJson(project);
        return FileUtil.writeStringToFile(data, file, false, false);
    }

    private boolean getBoolean(String str) {
        if (str != null && str.matches("true|1")) {
            return true;
        }
        return false;
    }
}
