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

import com.its.api.its.model.dto.facility.FcltFailTypeDto;
import com.its.api.its.model.dto.facility.TbFcltFailHsDto;
import com.its.api.its.service.facility.TbFcltFailHsService;
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.시설물 장애관리-0.장애내역")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/facility/fail-hs")
public class TbFcltFailHsController {

    private final TbFcltFailHsService service;

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

    @ApiOperation(value = "시설물 장애 내역 조회(TB_FCLT_FAIL_HS)", response = TbFcltFailHsDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/{fcltId}", produces = {"application/json; charset=utf8"})
    public List<TbFcltFailHsDto> findAllFailList(
            @ApiParam(name = "fcltId", value = "시설물 ID", example = "010800E406000006", required = true)
            @PathVariable final String fcltId) {
        return this.service.findAllFailList(fcltId);
    }

    @ApiOperation(value = "시설물 장애 내역 신규 장애이력일련번호 조회(TB_FCLT_FAIL_HS)", response = String.class)
    @GetMapping(value = "/new-hs-seq", produces = {"application/json; charset=utf8"})
    public String findNewHsSeq() {
        return this.service.findNewHsSeq();
    }

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

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

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

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

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

 }
