package com.its.api.its.controller.incident;

import com.its.api.its.model.dto.incident.IncdNewIdDto;
import com.its.api.its.model.dto.incident.TbIncdEstmSectDto;
import com.its.api.its.model.dto.incident.TbIncdOcrrDto;
import com.its.api.its.model.dto.incident.TbIncdOcrrVmsDto;
import com.its.api.its.model.dto.vms.TbVmsCtlrDto;
import com.its.api.its.service.incident.TbIncdEstmSectService;
import com.its.api.its.service.incident.TbIncdOcrrService;
import com.its.api.its.service.incident.TbIncdOcrrVmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "00.교통상황관리-2.돌발관리-1.돌발상황정보관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/manage/incident")
public class TbIncdOcrrController {

    private final TbIncdOcrrService service;
    private final TbIncdOcrrVmsService vmsService;
    private final TbIncdEstmSectService autoService;

    @ApiOperation(value = "신규생성돌발ID조회(TB_INCD_OCRR)", response = IncdNewIdDto.class)
    @GetMapping(value = "/new-id", produces = {"application/json; charset=utf8"})
    public IncdNewIdDto getNewIncdId() {
        return this.service.getNewIncdId();
    }

    @ApiOperation(value = "신규돌발정보조회(TB_INCD_OCRR)", response = TbIncdOcrrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/registered", produces = {"application/json; charset=utf8"})
    public List<TbIncdOcrrDto> findAllRegistered() {
        return this.service.findAllRegistered();
    }

    @ApiOperation(value = "진행중돌발정보조회(TB_INCD_OCRR)", response = TbIncdOcrrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/progress", produces = {"application/json; charset=utf8"})
    public List<TbIncdOcrrDto> findAllProgress() {
        return this.service.findAllProgress();
    }

    @ApiOperation(value = "진행/종료돌발 이력정보조회(TB_INCD_OCRR)", response = TbIncdOcrrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbIncdOcrrDto> findAllProgressHistory(
            @ApiParam(name = "FROM_DT", value = "조회시작시각(YYYYMMDDHH24)", example = "2021011200", required = true)
            @RequestParam String FROM_DT,
            @ApiParam(name = "TO_DT", value = "조회종료시각(YYYYMMDDHH24)", example = "2022061223", required = true)
            @RequestParam String TO_DT
    ) {
        String fromDt = FROM_DT + "0000";
        String toDt = TO_DT + "5959";
        return this.service.findAllProgressHistory(fromDt, toDt);
    }

    @ApiOperation(value = "VMS 돌발상황 정보 조회(TB_INCD_OCRR_VMS)", response = TbIncdOcrrVmsDto.class)
    @GetMapping(value = "/vms/incd/{id}", produces = {"application/json; charset=utf8"})
    public TbIncdOcrrVmsDto findIncdOcrrVmsById(
            @ApiParam(name = "id", value = "돌발 ID", example = "L08000000001", required = true)
            @PathVariable final String id) {
        return this.vmsService.findById(id);
    }

    @ApiOperation(value = "VMS 돌발상황 정보변경/생성-개별(TB_INCD_OCRR_VMS)", response = TbIncdOcrrVmsDto.class)
    @PostMapping(value = "/vms/incd/{id}", produces = {"application/json; charset=utf8"})
    public TbIncdOcrrVmsDto mergeIncdOcrrVmsInfo(
            @ApiParam(name = "id", value = "돌발 ID", example = "L08000000001", required = true)
            @PathVariable("id") String id,
            @ApiParam(name = "req", value = "VMS 돌발 정보", example = "", required = true)
            @RequestBody @Valid final TbIncdOcrrVmsDto.TbIncdOcrrVmsUpdReq req) {
        return this.vmsService.mergeInfo(req);
    }

    @ApiOperation(value = "돌발구간 VMS 목록조회(TB_INCD_OCRR)", response = TbVmsCtlrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/vms/link/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsCtlrDto> findAllVmsList(
            @ApiParam(name = "id", value = "링크 ID", example = "2280077300", required = true)
            @PathVariable Long id
    ) {
        return this.service.findAllVmsList(id);
    }



    @ApiOperation(value = "돌발상황 발생 개별조회(TB_INCD_OCRR)", response = TbIncdOcrrDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbIncdOcrrDto findById(@PathVariable final String id) {
        return this.service.findById(id);
    }

    @ApiOperation(value = "돌발상황 발생 정보변경/생성-개별(TB_INCD_OCRR)", response = TbIncdOcrrDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbIncdOcrrDto mergeInfo(@PathVariable("id") String id, @RequestBody @Valid final TbIncdOcrrDto.TbIncdOcrrUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "돌발상황 정보 오보처리(TB_INCD_OCRR)", response = TbIncdOcrrDto.class)
    @PostMapping(value = "/mis-info/{id}", produces = {"application/json; charset=utf8"})
    public TbIncdOcrrDto mergeMisInfo(
            @PathVariable("id") String id) {
        return this.service.misInfo(id);
    }

    @ApiOperation(value = "자동 돌발 정보 전체조회(TB_INCD_ESTM_SECT)", response = TbIncdEstmSectDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/auto", produces = {"application/json; charset=utf8"})
    public List<TbIncdEstmSectDto> findAllAutoIncd() {
        return this.autoService.findAll();
    }

/*
    @ApiOperation(value = "돌발상황 발생 정보변경(TB_INCD_OCRR)", response = TbIncdOcrrDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbIncdOcrrDto updateById(@PathVariable final String id, @RequestBody @Valid final TbIncdOcrrDto.TbIncdOcrrUpdReq req) {
        return this.service.updateById(id, req);
    }

    @ApiOperation(value = "돌발상황 발생 정보변경/생성-목록(TB_INCD_OCRR)", response = TbIncdOcrrDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbIncdOcrrDto> mergeInfoList(@RequestBody @Valid final List<TbIncdOcrrDto.TbIncdOcrrUpdReq> listReq) {
        return this.service.mergeInfoList(listReq);
    }

    @ApiOperation(value = "돌발상황 발생 정보삭제-개별(TB_INCD_OCRR)", response = TbIncdOcrrDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbIncdOcrrDto deleteDataById(@PathVariable("id") String id) {
        return this.service.deleteById(id);
    }

    @ApiOperation(value = "돌발상황 발생 정보삭제-목록(TB_INCD_OCRR)", response = TbIncdOcrrDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbIncdOcrrDto> deleteDataByIds(@RequestBody @Valid final List<String> ids) {
        return this.service.deleteByIds(ids);
    }
*/

}
