package com.its.op.controller.its.vms;

import com.its.op.dto.its.vms.TbVmsDsplSchDto;
import com.its.op.dto.its.vms.VmsFormDrawTrafDto;
import com.its.op.dto.its.vms.VmsFormIfscDto;
import com.its.op.service.its.vms.TbVmsDsplSchService;
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.Arrays;
import java.util.List;

@Api(tags = "12.VMS-3.스케줄관리-1.자동 스케줄 관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/vms/schedule/auto")
public class TbVmsDsplSchAutoController {

    private final TbVmsDsplSchService service;

    /**
     * VMS 제어기 관리 번호로 폼 표출 스케줄 목록 조회
     * @param id
     * @return
     */
    @ApiOperation(value = "VMS 폼 스케줄 목록 조회(TB_VMS_DSPL_SCH)", response = TbVmsDsplSchDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsDsplSchDto> findAllVmsDsplSchedule(
            @ApiParam(name = "id", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long id
    ) {
        return this.service.findAllVmsDsplSchedule(id);
    }

    /**
     * 교통정보 폼 스케쥴 정보제공구간 요청
     * @param ctlrId
     * @param schType
     * @return
     */
    @ApiOperation(value = "VMS 제어기 유형별 폼 스케줄 목록 조회(TB_VMS_DSPL_SCH)", response = VmsFormIfscDto.class)
    @GetMapping(value = "/form/ifsc/{ctlrId}/{schType}/{phase}", produces = {"application/json; charset=utf8"})
    public VmsFormIfscDto findAllVmsFormIfsc(
            @ApiParam(name = "ctlrId", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long ctlrId,
            @ApiParam(name = "schType", value = "VMS 스케쥴 코드(0:교통정보,1:돌발,2:공사/행사,3:홍보,4:우회도로,7:정체,8:재난안전)", example = "0", required = true)
            @PathVariable final Integer schType,
            @ApiParam(name = "phase", value = "스케쥴 PHASE", example = "1", required = true)
            @PathVariable final Integer phase
    ) {
        return this.service.findAllVmsFormIfsc(ctlrId, "A", schType, phase);
    }


    @ApiOperation(value = "VMS 제어기 유형별 폼 스케줄 목록 조회(TB_VMS_DSPL_SCH)", response = TbVmsDsplSchDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list-form/{ctlrNmbr}/{schType}", produces = {"application/json; charset=utf8"})
    public List<TbVmsDsplSchDto> findAllVmsDsplSchedule(
            @ApiParam(name = "ctlrNmbr", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long ctlrNmbr,
            @ApiParam(name = "schType", value = "VMS 스케쥴 코드(0:교통정보,1:돌발,2:공사/행사,3:홍보,4:우회도로,7:정체,8:재난안전)", example = "0", required = true)
            @PathVariable final Integer schType
    ) {
        // 교통정보 ("0");
        // 돌발 ("1");
        // 공사/행사 ("2");
        // 홍보 ("3");
        // 우회도로 ("4");
        // 정체 ("7");
        // 재난안전 ("8");
        List<Integer> trfcSituTypeCd = Arrays.asList(schType);
        return this.service.findAllVmsDsplSchedule(ctlrNmbr, "A", trfcSituTypeCd);
    }
    // 교통정보 폼 그리기
    @ApiOperation(value = "VMS 교통정보 폼 그리기", response = VmsFormDrawTrafDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/list/traffic/draw/{id}/{form}", produces = {"application/json; charset=utf8"})
    public VmsFormDrawTrafDto drawTrafficForm(
            @ApiParam(name = "id", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long id,
            @ApiParam(name = "form", value = "VMS 폼 ID", example = "10092", required = true)
            @PathVariable final Integer form,
            @RequestBody @Valid final VmsFormDrawTrafDto.VmsFormDrawTrafReq req
    ) {
        return this.service.drawTrafficForm(id, form, req);
    }

    // 교통정보
    @ApiOperation(value = "VMS 폼 정보 조회-교통정보(TB_VMS_DSPL_SCH)", response = TbVmsDsplSchDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/traffic/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsDsplSchDto> findAllTrafficByVmsType(
            @ApiParam(name = "id", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long id
    ) {
        return this.service.findAllTraffic(id);
    }

    // 정체
    @ApiOperation(value = "VMS 폼 정보 조회-정체(TB_VMS_DSPL_SCH)", response = TbVmsDsplSchDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/congest/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsDsplSchDto> findAllCongestByVmsType(
            @ApiParam(name = "id", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long id
    ) {
        return this.service.findAllCongest(id);
    }

    // 돌발
    @ApiOperation(value = "VMS 폼 정보 조회-돌발(TB_VMS_DSPL_SCH)", response = TbVmsDsplSchDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/incident/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsDsplSchDto> findAllIncidentByVmsType(
            @ApiParam(name = "id", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long id
    ) {
        return this.service.findAllIncident(id);
    }

    // 공사/행사
    @ApiOperation(value = "VMS 폼 정보 조회-공사/행사(TB_VMS_DSPL_SCH)", response = TbVmsDsplSchDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/event/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsDsplSchDto> findAllEventByVmsType(
            @ApiParam(name = "id", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long id
    ) {
        return this.service.findAllEvent(id);
    }

    // 홍보
    @ApiOperation(value = "VMS 폼 정보 조회-홍보(TB_VMS_DSPL_SCH)", response = TbVmsDsplSchDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/notice/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsDsplSchDto> findAllHongboByVmsType(
            @ApiParam(name = "id", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long id
    ) {
        return this.service.findAllHongbo(id);
    }

    // 우회도로
    @ApiOperation(value = "VMS 폼 정보 조회-우회도로(TB_VMS_DSPL_SCH)", response = TbVmsDsplSchDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/detour/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsDsplSchDto> findAllDetourByVmsType(
            @ApiParam(name = "id", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long id
    ) {
        return this.service.findAllDetour(id);
    }

    // 재난안전
    @ApiOperation(value = "VMS 폼 정보 조회-재난안전(TB_VMS_DSPL_SCH)", response = TbVmsDsplSchDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/safety/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsDsplSchDto> findAllSafetyByVmsType(
            @ApiParam(name = "id", value = "VMS 제어기 관리번호", example = "10005", required = true)
            @PathVariable final Long id
    ) {
        return this.service.findAllSafety(id);
    }

}
