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

import com.its.api.its.model.dto.facility.TbFcltFailRparHsDto;
import com.its.api.its.model.entity.facility.TbFcltFailRparHsKey;
import com.its.api.its.service.facility.TbFcltFailRparHsService;
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.시설물-3.시설물 장애관리-1.장애조치내역")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/facility/fail-pair")
public class TbFcltFailRparHsController {

    private final TbFcltFailRparHsService service;

    @ApiOperation(value = "시설물 장애 조치 내역 조회(TB_FCLT_FAIL_RPAR_HS)", response = TbFcltFailRparHsDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/{failHsSeq}", produces = {"application/json; charset=utf8"})
    public List<TbFcltFailRparHsDto> findAllFailHsList(
            @ApiParam(name = "failHsSeq", value = "장애이력 일련번호", example = "2022030001", required = true)
            @PathVariable final String failHsSeq) {
        return this.service.findAllFailHsList(failHsSeq);
    }

    @ApiOperation(value = "시설물 장애 조치 내역 정보변경(TB_FCLT_FAIL_RPAR_HS)", response = TbFcltFailRparHsDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbFcltFailRparHsDto updateById(@PathVariable final TbFcltFailRparHsKey id, @RequestBody @Valid final TbFcltFailRparHsDto.TbFcltFailRparHsUpdReq req) {
        return this.service.updateById(id, req);
    }

    @ApiOperation(value = "시설물 장애 조치 내역 정보변경/생성-목록(TB_FCLT_FAIL_RPAR_HS)", response = TbFcltFailRparHsDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbFcltFailRparHsDto> mergeInfoList(@RequestBody @Valid final List<TbFcltFailRparHsDto.TbFcltFailRparHsUpdReq> listReq) {
        return this.service.mergeInfoList(listReq);
    }

    @ApiOperation(value = "시설물 장애 조치 내역 정보변경/생성-개별(TB_FCLT_FAIL_RPAR_HS)", response = TbFcltFailRparHsDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbFcltFailRparHsDto mergeInfo(@PathVariable("id") TbFcltFailRparHsKey id, @RequestBody @Valid final TbFcltFailRparHsDto.TbFcltFailRparHsUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "시설물 장애 조치 내역 정보삭제-개별(TB_FCLT_FAIL_RPAR_HS)", response = TbFcltFailRparHsDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbFcltFailRparHsDto deleteDataById(@PathVariable("id") TbFcltFailRparHsKey id) {
        return this.service.deleteById(id);
    }

    @ApiOperation(value = "시설물 장애 조치 내역 정보삭제-목록(TB_FCLT_FAIL_RPAR_HS)", response = TbFcltFailRparHsDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbFcltFailRparHsDto> deleteDataByIds(@RequestBody @Valid final List<TbFcltFailRparHsKey> ids) {
        return this.service.deleteByIds(ids);
    }

}
