package com.its.op.controller.its.wcam;

import com.its.op.dto.its.common.NewIdLongDto;
import com.its.op.dto.its.wcam.TbWcamCtlrDto;
import com.its.op.service.its.wcam.TbWcamCtlrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 = "10.웹카메라-1.웹카메라 관리-01.기본정보관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/wcam/manager/info")
public class TbWcamCtlrController {

    private final TbWcamCtlrService service;

    @ApiOperation(value = "웹 카메라 전체조회(TB_WCAM_CTLR)", response = TbWcamCtlrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbWcamCtlrDto> findAllList() {
        return this.service.findAllList();
    }

    @ApiOperation(value = "웹 카메라 개별조회(TB_WCAM_CTLR)", response = TbWcamCtlrDto.class)
    @GetMapping(value = "/{wcamCtlrNmbr}", produces = {"application/json; charset=utf8"})
    public TbWcamCtlrDto findById(@PathVariable("wcamCtlrNmbr") final Long wcamCtlrNmbr) {
        return this.service.findById(wcamCtlrNmbr);
    }

    @ApiOperation(value = "웹 카메라 정보변경/생성-개별(TB_WCAM_CTLR)", response = TbWcamCtlrDto.class)
    @PostMapping(value = "/{wcamCtlrNmbr}", produces = {"application/json; charset=utf8"})
    public TbWcamCtlrDto mergeInfo(@PathVariable("wcamCtlrNmbr") final Long wcamCtlrNmbr, @RequestBody @Valid final TbWcamCtlrDto.TbWcamCtlrUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "웹 카메라 정보삭제-개별(TB_WCAM_CTLR)", response = TbWcamCtlrDto.class)
    @DeleteMapping(value = "/{wcamCtlrNmbr}", produces = {"application/json; charset=utf8"})
    public TbWcamCtlrDto deleteDataById(@PathVariable("wcamCtlrNmbr") final Long wcamCtlrNmbr) {
        return this.service.deleteById(wcamCtlrNmbr);
    }

    @ApiOperation(value = "신규 CCTV 제어기 ID 조회(TB_CCTV_CTLR)", response = NewIdLongDto.class)
    @GetMapping(value = "/new-id", produces = {"application/json; charset=utf8"})
    public NewIdLongDto getNewNmbr() {
        return this.service.getNewNmbr();
    }

}
