package cn.com.poc.ai_data_audit.rest.impl;

import cn.com.poc.ai_data_audit.rest.DataAuditRest;
import cn.com.poc.ai_data_audit.dto.BizAiDataAuditFileDto;
import cn.com.poc.ai_data_audit.dto.FileUploadConfirmDto;
import cn.com.poc.ai_data_audit.dto.FileUploadDto;
import cn.com.poc.ai_data_audit.dto.FileUploadReturnDto;
import cn.com.poc.ai_data_audit.service.BizAiDataAuditTaskService;
import cn.com.poc.common.service.BosConfigService;
import cn.com.poc.common.utils.StringUtils;
import cn.com.poc.thirdparty.resource.demand.ai.aggregate.MinerUOcrService;
import cn.com.poc.thirdparty.resource.demand.ai.entity.orc.minerU.MinerUOcrResponse;
import cn.com.poc.thirdparty.resource.demand.ai.entity.orc.minerU.MinerUOcrResult;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author：Roger Wu
 * @name：FileUploadDtoImpl
 * @Date：2025-10-29 21:29
 */
@Component
public class DataAuditRestImpl implements DataAuditRest {

    @Resource
    private BizAiDataAuditTaskService bizAiDataAuditTaskService;

    @Resource
    private MinerUOcrService minerUOcrService;

    @Override
    public List<FileUploadReturnDto> fileUpload(List<FileUploadDto> fileUploadDtoList) throws Exception {
        if (CollectionUtils.isEmpty(fileUploadDtoList)) {
            throw new Exception("please upload files");
        }
        // 获取单个文件的文件名
        List<String> fileNames = fileUploadDtoList.stream()
                .map(item -> item.getFileName())
                .collect(Collectors.toList());

        Map<String, String> fileNameMap = new HashMap<>();
//        fileNameMap.put("DOC-01","Work Permit Application Details");
//        fileNameMap.put("DOC-02","Work Permit Extension Details");
        fileNameMap.put("DOC-03", "Work Method Statement");
        fileNameMap.put("DOC-04", "Safety Method Statement or Safety Plan");
        fileNameMap.put("DOC-05", "Risk Assessment");
        fileNameMap.put("DOC-06", "Work Programme");
        fileNameMap.put("DOC-07", "Location Plan");
        fileNameMap.put("DOC-08", "HKIA Contractor Safety (Construction & Maintenance) Training Record");
        fileNameMap.put("DOC-09", "HKIA BRAAS Check Form or BRAAS Exemption Declaration Form");
        fileNameMap.put("DOC-10", "Premises Endorser Declaration Form for Work Permit Application");
        fileNameMap.put("DOC-11", "OCWIP");
        fileNameMap.put("DOC-12", "Insurance");
        fileNameMap.put("DOC-13", "Pay-in-Slip for Work Permit Processing Fee");
        fileNameMap.put("DOC-14", "HKIA APM Safety Video Training and Examination Record");
        fileNameMap.put("DOC-15", "Aerodrome Safety Risk Assessment");
        fileNameMap.put("DOC-16", "System Change Request (SCR)");
        fileNameMap.put("DOC-17", "CCTV Equipment Configuration Request Form");
        fileNameMap.put("DOC-18", "Permit to Dig");
        fileNameMap.put("DOC-19", "Temporary Traffic Management Plan");


        //执行文件名匹配
        //执行类型匹配
        MinerUOcrResponse minerUOcrResponse = new MinerUOcrResponse();
//        minerUOcrResponse.setFile();
//        minerUOcrResponse.setOutput_dir();
//        minerUOcrResponse.setLang_list();
//        minerUOcrResponse.setBackend();
//        minerUOcrResponse.setParse_method();
//        minerUOcrResponse.setFormula_enable();
//        minerUOcrResponse.setTable_enable();
//        minerUOcrResponse.setServer_url();
//        minerUOcrResponse.setReturn_md();
//        minerUOcrResponse.setReturn_middle_json();
//        minerUOcrResponse.setReturn_model_output();
//        minerUOcrResponse.setReturn_content_list();
//        minerUOcrResponse.setReturn_images();
//        minerUOcrResponse.setResponse_format_zip();
//        minerUOcrResponse.setStart_page_id();
//        minerUOcrResponse.setEnd_page_id();

        MinerUOcrResult minerUOcrResult = minerUOcrService.fileParse(minerUOcrResponse);
        return new ArrayList<FileUploadReturnDto>();
    }

    @Override
    public void createDataAuditTask(FileUploadConfirmDto fileUploadConfirmDto) throws Exception {

        String taskName = "Data Audit Task";

        bizAiDataAuditTaskService.createDataAuditTask(taskName, fileUploadConfirmDto);
    }


}
