package com.its.op.controller.its.facility;

import com.its.op.dto.its.common.NewIdLongDto;
import com.its.op.dto.its.facility.FcltWorkStepDto;
import com.its.op.dto.its.facility.TbFcltInfrDto;
import com.its.op.dto.its.facility.UnRegisteredFcltInfrDto;
import com.its.op.service.its.facility.TbFcltInfrService;
import com.sun.istack.Nullable;
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 = "01.시설물관리-1.시설물-1.시설물 정보관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/facility/manager/info")
public class TbFcltInfrController {

    private final TbFcltInfrService service;

    @ApiOperation(value = "시설물 장애 유형 코드 조회", response = FcltWorkStepDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/work-step", produces = {"application/json; charset=utf8"})
    public List<FcltWorkStepDto> findAllFailList() {
        return this.service.findAllWorkStep();
    }

    @ApiOperation(value = "시설물 정보 전체조회(TB_FCLT_INFR)", response = TbFcltInfrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbFcltInfrDto> findAllList(
            @ApiParam(name = "fcltType", value = "시설물유형", example = "CCTV", required = false)
            @RequestParam(required = false, name="fcltType") @Nullable final String fcltType
    ) {
        return this.service.findAllList(fcltType);
    }

    @ApiOperation(value = "미등록 시설물 정보 전체조회(TB_FCLT_INFR)", response = UnRegisteredFcltInfrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/unreg", produces = {"application/json; charset=utf8"})
    public List<UnRegisteredFcltInfrDto> findAllUnRegisteredList(
            @ApiParam(name = "fcltType", value = "시설물유형", example = "CCTV", required = false)
            @RequestParam(required = false, name="fcltType") @Nullable final String fcltType
    ) {
        return this.service.findAllUnRegisteredList(fcltType);
    }

    @ApiOperation(value = "시설물 정보 정보등록(TB_FCLT_INFR)", response = TbFcltInfrDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/reg", produces = {"application/json; charset=utf8"})
    public List<TbFcltInfrDto> mergeRegInfoList(@RequestBody @Valid final List<UnRegisteredFcltInfrDto.TbRegFcltInfrUpdReq> listReq) {
        return this.service.mergeRegInfoList(listReq);
    }

    @ApiOperation(value = "시설물 정보 개별조회(TB_FCLT_INFR)", response = TbFcltInfrDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbFcltInfrDto findById(@PathVariable final Long id) {
        return this.service.findById(id);
    }

    @ApiOperation(value = "시설물 정보 정보변경(TB_FCLT_INFR)", response = TbFcltInfrDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbFcltInfrDto updateById(@PathVariable final Long id, @RequestBody @Valid final TbFcltInfrDto.TbFcltInfrUpdReq req) {
        return this.service.updateById(id, req);
    }

    @ApiOperation(value = "시설물 정보 정보변경/생성-목록(TB_FCLT_INFR)", response = TbFcltInfrDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbFcltInfrDto> mergeInfoList(@RequestBody @Valid final List<TbFcltInfrDto.TbFcltInfrUpdReq> listReq) {
        return this.service.mergeInfoList(listReq);
    }

    @ApiOperation(value = "시설물 정보 정보변경/생성-개별(TB_FCLT_INFR)", response = TbFcltInfrDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbFcltInfrDto mergeInfo(@PathVariable("id") Long id, @RequestBody @Valid final TbFcltInfrDto.TbFcltInfrUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "시설물 정보 정보삭제-개별(TB_FCLT_INFR)", response = TbFcltInfrDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbFcltInfrDto deleteDataById(@PathVariable("id") Long id) {
        return this.service.deleteById(id);
    }

    @ApiOperation(value = "시설물 정보 정보삭제-목록(TB_FCLT_INFR)", response = TbFcltInfrDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbFcltInfrDto> deleteDataByIds(@RequestBody @Valid final List<Long> ids) {
        return this.service.deleteByIds(ids);
    }

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


}
