package com.tsi.monitoring.controller;

import com.tsi.monitoring.service.SectionService;
import com.tsi.monitoring.service.UtisService;
import com.tsi.monitoring.vo.CenterVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

@Controller
@RequiredArgsConstructor
@Slf4j
public class MainController {

    private final SectionService sectionService;
    private final UtisService utisService;
    /**
     * TODO Region Center Link State Info List & Receive History Info List
     * @param model model
     * @return monitoring.html
     */
    @GetMapping({"/", "/monitoring.do"})
    public String home(Model model) {
        return "monitoring";
    }

    @GetMapping("/processStatusMonitoring.do")
    public String processStatusMonitoring() {
        return "process_stat_monitoring";
    }

    @GetMapping("/popupDetailLogs.do")
    public String popupDetailLogs(@RequestParam String centerId, Model model) {
        model.addAttribute("centerInfo", this.sectionService.getCenterInfoWithId(centerId));
        model.addAttribute("statistics", this.sectionService.getAllStatistics(centerId));
        return "popupDetailLogs";
    }

    @GetMapping("/popupLinkedDetailLogs.do")
    public String popupLinkedDetailLogs(Model model) {
        model.addAttribute("statistics", this.utisService.getAllStatistics());
        return "popupLinkedDetailLogs";
    }

    /**
     * @param model model
     * @return
     */
    @GetMapping("/rcvIncdStat.do")
    public String rcvIncdStatistics(Model model) {
//        return "rcv-incd-statistics";
        model.addAttribute("title", "도로공사 돌발정보 수집 이력 조회");
        model.addAttribute("selectPath", "normal-select-template");
        model.addAttribute("tablePath", "rcv_incd_table");
        model.addAttribute("type", "incd");
        return "statistics_template";
    }

    /**
     * @param model model
     * @return
     */
    @GetMapping("/centerSendRcvCountStat.do")
    public String centerSendRcvCountStatistics(Model model) {
        model.addAttribute("list", this.sectionService.getCenterList());
        model.addAttribute("title", "지역센터 일별 제공/수집 전송 이력");
        model.addAttribute("selectPath", "send_res_center_select");
        model.addAttribute("tablePath", "snd_rcv_center_table");
        model.addAttribute("type", "snd_rcv_center");
        return "statistics_template";
    }

    /**
     * @param model model
     * @return rcv-send-center-statistics.html
     */
    @GetMapping("/centerStat.do")
    public String centerStat(Model model) {
        model.addAttribute("centerInfo", this.sectionService.getCenterList());
        return "rcv-send-center-statistics";
    }

    /**
     * @param model model
     * @return rcv-nts-statistics.html
     */
    @GetMapping("/rcvNtsStat.do")
    public String rcvNtsStat(Model model) {
        model.addAttribute("title", "동부NTS 교통정보 수집 이력 조회");
        model.addAttribute("selectPath", "normal-select-template");
        model.addAttribute("tablePath", "rcv_nts_table");
        model.addAttribute("type", "nts");
        return "statistics_template";
    }

   /**
     * @param model model
     * @return
     */
    @GetMapping("/sndMoctStat.do")
    public String sndMoctStat(Model model) {
        model.addAttribute("title", "민간 정보 제공 이력 조회");
        model.addAttribute("selectPath", "normal-select-template");
        model.addAttribute("tablePath", "snd_moct_table");
        model.addAttribute("type", "moct");
        return "statistics_template";
    }
   /**
     * @param model model
     * @return
     */
    @GetMapping("/sndTrafStat.do")
    public String sndTrafStat(Model model) {
        model.addAttribute("title", "국토부 교통정보 제공 이력 조회");
        model.addAttribute("selectPath", "molt-select-template");
        model.addAttribute("tablePath", "snd_molit_table");
        model.addAttribute("type", "snd_molit");
        return "statistics_template";
    }

   /**
     * @param model model
     * @return
     */
    @GetMapping("/rcvTrafStat.do")
    public String rcvTrafStat(Model model) {
        model.addAttribute("title", "국토부 교통정보 수집 이력 조회");
        model.addAttribute("selectPath", "molt-select-template");
        model.addAttribute("tablePath", "rcv_molit_table");
        model.addAttribute("type", "rcv_molit");
        return "statistics_template";
    }

   /**
     * @param model model
     * @return
     */
    @GetMapping("/policeMoctTrafStat.do")
    public String policeMoctTrafStat(Model model) {
//        model.addAttribute("title", "국토부 민간정보 수집 이력 조회");
        model.addAttribute("title", "국토부 민간교통정보 수집이력");
        model.addAttribute("selectPath", "molt-select-template");
        model.addAttribute("tablePath", "rcv_moct_table");
        model.addAttribute("type", "rcv_moct");
        return "statistics_template";
    }

   /**
     * @param model model
     * @return sig-comm-statistics.htm,l
     */
    @GetMapping("/sigCommStat.do")
    public String sigCommStat(Model model) {
        model.addAttribute("list", this.sectionService.getSigRegionInfo());
        model.addAttribute("title", "지역센터 신호연계 통신이력 조회");
        model.addAttribute("selectPath", "sig-comm-select");
        model.addAttribute("tablePath", "sig_comm_table");
        model.addAttribute("type", "sig_comm");
        return "statistics_template";
//        return "sig-comm-statistics";
    }

    /**
     * @param model model
     * @return
     */
    @GetMapping("/confTrafficWeight.do")
    public String confColWeight(Model model) {
        model.addAttribute("type", this.utisService.getAnalysisType());
        model.addAttribute("list", this.utisService.getTrafficWeightInfo());
        return "conf-traffic-weight";
    }

    /**
     * TODO Preference Info List
     * @param model model
     * @return preference.html
     */
    @GetMapping("/preference.do")
    public String preference(Model model) {
        return "preference";
    }

}
