package com.tsi.monitoring.controller;

import com.tsi.monitoring.service.UtisService;
import com.tsi.monitoring.vo.ResultVo;
import com.tsi.monitoring.vo.TrafficWeightConfVo;
import com.tsi.monitoring.vo.TrafficWeightVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/conf")
public class ConfTrafficWeightController {
    private final UtisService utisService;

    @PostMapping("/getTrafficWeightInfo")
    @ResponseBody
    public List<TrafficWeightConfVo> getTrafficWeightInfo() {
        return this.utisService.getTrafficWeightInfo();
    }

    @PostMapping("/updateTrafficWeightInfo")
    @ResponseBody
    public ResultVo getTrafficWeightInfo(@RequestBody TrafficWeightVo param) {
        try {
            return this.utisService.updateTrafficWeightInfo(param);
        }
        catch (RuntimeException e) {
            log.error("가중치 정보 업데이트 실패", e);
            ResultVo errorVo = new ResultVo();
            errorVo.setSuccess("F");
            errorVo.setMsg("요청하신 수집원별 가중치 정보 설정 중 오류가 발생하였습니다.");
            return errorVo;
        }
    }

    @PostMapping("/getAnalysisType")
    @ResponseBody
    public Integer getAnalysisType() {
        return this.utisService.getAnalysisType();
    }
}
