package com.base.task.handler;

import com.base.task.model.input.Input;
import com.base.task.model.Task;

import java.io.*;
import java.text.ParseException;

public interface TaskHandler {

    default boolean input(Input input, String path, String inputFileName)  {
        try{
            File file = new File(path+"/"+inputFileName);
            if (file.exists()){
               if (!file.delete()){
                   return false;
               }
            }
            if (!file.createNewFile()){
                return false;
            }
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
            bufferedWriter.write(input.getDataInput());
            bufferedWriter.flush();
            bufferedWriter.close();
        }catch (Exception e){
            System.out.println(e);
            return false;
        }
            return true;
    }

    void taskExecute(Task task) throws IOException, ParseException;

}
