package core.operation;

import core.user.User;
import dao.DBManagement;

import java.io.File;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class DownloadFile extends Operation{
    @Override
    public Map<String, Object> execute(User subject) throws Exception {
        String table = (String) this.getOptions().get("file_type");
        Map<String,String> limits = (Map<String, String>) this.getOptions().get("limits");
        String field = core.operation.utils.Utils.getFileField(table);
        List<String> ls = new ArrayList<>();
        ls.add(field);
        List<String[]> resultLs = DBManagement.select(ls,table,limits,0,1);
        String filePath = resultLs.get(0)[0];
        File file = new File(filePath);
        this.getOptions().put("file",file);
        return this.getOptions();
    }
}
