package com.its.vms.api.controller;

import com.its.vms.api.dto.*;
import com.its.vms.api.service.VmsControlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@Api(tags = "1.VMS-0.제어")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/vms/control")
public class VmsControlController {

    private final VmsControlService service;

//    @ApiOperation(value = "TEST", response = CctvStatusDto.CctvStatusNotifyDtoRes.class)
//    @GetMapping(value = "/status/notify/{id}", produces = {"application/json; charset=utf8"})
//    public CctvStatusDto.CctvStatusNotifyDtoRes notifyStatus(
//            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
//            @PathVariable("id") Long id) {
//        return this.service.notifyStatus(id);
//    }

    @ApiOperation(value = "VMS 환경 파라미터 조회", response = CctvParamControlDto.CctvParamValueRes.class)
    @GetMapping(value = "/param-qry/{id}", produces = {"application/json; charset=utf8"})
    public CctvParamControlDto.CctvParamValueRes requestParam(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id) {
        return this.service.requestParam(id);
    }

    @ApiOperation(value = "VMS 환경 파라미터 설정", response = CctvParamControlDto.CctvParamControlRes.class)
    //@PostMapping(value = "/param-set/{id}", produces = {"application/json; charset=utf8"})
    @RequestMapping(value = "/param-set/{id}", method = {RequestMethod.GET, RequestMethod.POST})
    public CctvParamControlDto.CctvParamControlRes controlParam(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id,
            @ApiParam(name = "req", value = "CCTV PARAMETER 설정 정보", example = "[ADMIN]", required = true)
            @RequestBody @Valid final CctvParamControlDto.CctvParamControlReq req) {
        return this.service.controlParam(id, req);
    }

    @ApiOperation(value = "VMS 상태 조회", response = CctvStatusDto.CctvStatusDtoRes.class)
    @GetMapping(value = "/status/{id}", produces = {"application/json; charset=utf8"})
    public CctvStatusDto.CctvStatusDtoRes requestStatus(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id) {
        return this.service.requestStatus(id);
    }

    @ApiOperation(value = "VMS 현재위치정보 조회", response = CctvPresetControlDto.CctvPresetValueRes.class)
    @GetMapping(value = "/preset-value/{id}", produces = {"application/json; charset=utf8"})
    public CctvPresetControlDto.CctvPresetValueRes requestPresetValue(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id) {
        return this.service.requestPresetValue(id);
    }

    @ApiOperation(value = "VMS PTZ 제어", response = CctvPtzControlDto.CctvPtzControlRes.class)
    //@PostMapping(value = "/ptz/{id}", produces = {"application/json; charset=utf8"})
    @RequestMapping(value = "/ptz/{id}", method = {RequestMethod.GET, RequestMethod.POST})
    public CctvPtzControlDto.CctvPtzControlRes controlPtz(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id,
            @ApiParam(name = "req", value = "VMS PTZ 제어 정보", example = "[tilt-up, start, 20, ADMIN]", required = true)
            @RequestBody @Valid final CctvPtzControlDto.CctvControlPtzReq req) {
        return this.service.controlPtz(id, req);
    }

    @ApiOperation(value = "VMS Preset 제어", response = CctvPresetControlDto.CctvPresetControlRes.class)
    //@PostMapping(value = "/preset/{id}", produces = {"application/json; charset=utf8"})
    @RequestMapping(value = "/preset/{id}", method = {RequestMethod.GET, RequestMethod.POST})
    public CctvPresetControlDto.CctvPresetControlRes controlPreset(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id,
            @ApiParam(name = "req", value = "VMS Preset 제어 정보", example = "[preset, call, 1, 0, 0, ADMIN]", required = true)
            @RequestBody @Valid final CctvPresetControlDto.CctvPresetControlReq req) {
        return this.service.controlPreset(id, req);
    }

    @ApiOperation(value = "VMS 가변 문자 설정", response = CctvVarCharControlDto.CctvVarCharControlRes.class)
    //@PostMapping(value = "/var-char-set/{id}", produces = {"application/json; charset=utf8"})
    @RequestMapping(value = "/var-char-set/{id}", method = {RequestMethod.GET, RequestMethod.POST})
    public CctvVarCharControlDto.CctvVarCharControlRes controlVarCharSet(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id,
            @ApiParam(name = "req", value = "VMS 가변문자 설정 정보", example = "[preset, call, 1, 0, 0, ADMIN]", required = true)
            @RequestBody @Valid final CctvVarCharControlDto.CctvVarCharControlSetReq req) {
        return this.service.controlVarCharSet(id, req);
    }

    @ApiOperation(value = "VMS 가변 문자 삭제", response = CctvVarCharControlDto.CctvVarCharControlRes.class)
    //@PostMapping(value = "/var-char-del/{id}", produces = {"application/json; charset=utf8"})
    @RequestMapping(value = "/var-char-del/{id}", method = {RequestMethod.GET, RequestMethod.POST})
    public CctvVarCharControlDto.CctvVarCharControlRes controlVarCharDel(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id,
            @ApiParam(name = "req", value = "VMS 가변문자 삭제 정보", example = "[preset, call, 1, 0, 0, ADMIN]", required = true)
            @RequestBody @Valid final CctvVarCharControlDto.CctvVarCharControlDelReq req) {
        return this.service.controlVarCharDel(id, req);
    }

    @ApiOperation(value = "VMS RESET", response = CctvControlDto.CctvControlResetRes.class)
    //@PostMapping(value = "/reset/{id}", produces = {"application/json; charset=utf8"})
    @RequestMapping(value = "/reset/{id}", method = {RequestMethod.GET, RequestMethod.POST})
    public CctvControlDto.CctvControlResetRes controlReset(
            @ApiParam(name = "id", value = "제어기번호", example = "1001", required = true)
            @PathVariable("id") Long id,
            @ApiParam(name = "req", value = "VMS 제어기 리셋", example = "[0/1, ADMIN]", required = true)
            @RequestBody @Valid final CctvControlDto.CctvControlResetReq req) {
        return this.service.controlReset(id, req);
    }

}
