package com.mooctest.controller;

import com.mooctest.cluster.ClusterAnalyzer;
import com.mooctest.cluster.Group;
import com.mooctest.event.EventUtil;
import com.mooctest.event.TaskStartEvent;
import com.mooctest.image.ImageDownload;
import com.mooctest.data.BugDTO;
import com.mooctest.data.DiffImg;
import com.mooctest.data.DiffText;
import com.mooctest.data.ReportDTO;
import com.mooctest.model.AggTaskStatus;
import com.mooctest.model.MasterReport;
import com.mooctest.nlp.DistanceMatrix;
import com.mooctest.service.*;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toMap;

@RestController
public class AggController {
    @Autowired
    BugReportService bugReportService;

    @Autowired
    MasterReportService masterReportService;


    @Autowired
    AggTaskStatusService aggTaskStatusService;

    @Autowired
    EventUtil eventUtil;
    @GetMapping("/aggregate_info")
    public MasterReport getAggInfo(@RequestParam("bugId") String bugId) {
        return masterReportService.getByBugId(bugId);
    }

    @GetMapping("/aggregate")
    public String aggregate(@RequestParam("examId") long examId,
                            @RequestParam("caseId") long caseId) throws IOException {
        TaskStartEvent e = new TaskStartEvent(examId, caseId);
        eventUtil.post(e);

        return "ok";
    }

    @GetMapping("/agg_task_status")
    public int getAggStatus(@RequestParam("examId") long examId,
                            @RequestParam("caseId") long caseId) {
        AggTaskStatus status = aggTaskStatusService.getByTaskId(examId, caseId);
        if (status == null) {
            return 0;
        }
        return status.getStatus();
    }






}
