package com.its.api.its.controller.facility;

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

    private final TbFcltInfrService service;

    @ApiOperation(value = "시설물 정보 전체조회(TB_FCLT_INFR)", response = TbFcltInfrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbFcltInfrDto> findAllList() {
        return this.service.findAllList();
    }

    @ApiOperation(value = "미등록 시설물 정보 전체조회(TB_FCLT_INFR)", response = UnRegisteredFcltInfrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/unreg", produces = {"application/json; charset=utf8"})
    public List<UnRegisteredFcltInfrDto> findAllUnRegisteredList() {
        return this.service.findAllUnRegisteredList();
    }

    @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 String 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 String 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") String 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") String 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<String> ids) {
        return this.service.deleteByIds(ids);
    }

}
