package xyz.wbsite.dbtool.javafx.manger.callable;

import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager;
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.po.AbstractDBmapper;
import xyz.wbsite.dbtool.javafx.po.AndroidOption;
import xyz.wbsite.dbtool.javafx.tool.Tool;
import xyz.wbsite.dbtool.web.frame.utils.ZipUtil;

import javax.validation.constraints.NotNull;
import java.io.File;
import java.util.concurrent.Callable;

public class AndroidCallable implements Callable {

    private Tool tool = new Tool();
    private String path;
    private AndroidOption option;

    private FreeMarkerManager freeMarkerManager;

    public AndroidCallable(@NotNull String path, AndroidOption option) {
        this.path = path;
        this.option = option;
        this.freeMarkerManager = ManagerFactory.getFreeMarkerManager();
    }

    private AbstractDBmapper dBmapper;

    public Boolean call() throws Exception {
        // 文件输出文件
        File zipFile = new File(path, "wbui.zip");
        // 文件输出目录
        File dir = new File(path, "wbui");
        // 清空输出目录
        Tool.clear(dir);
        System.out.println("清空文件" + dir.getAbsolutePath());
        // 输出文件
        Tool.outputResource("Android/wbui.zip", zipFile);
        // 解压文件
        new ZipUtil().unZip(zipFile, new File(path));
        // 删除文件
        zipFile.delete();
        System.out.println("删除文件" + zipFile.getAbsolutePath());
        return true;
    }
}
