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.VueOption;
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 VueCallable implements Callable {

    private String path;
    private VueOption option;

    private FreeMarkerManager freeMarkerManager;

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

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