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

import com.its.op.dto.its.common.NewIdLongDto;
import com.its.op.dto.its.facility.TbFcltFailActDto;
import com.its.op.entity.its.facility.TbFcltFailActKey;
import com.its.op.service.its.facility.TbFcltFailActService;
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.시설물관리-3.시설물 상태관리-2.시설물 장애 조치 등록")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/facility/fail/plan/act")
public class TbFcltFailActController {

    private final TbFcltFailActService service;

    @ApiOperation(value = "시설물 장애 발생 조치 정보 전체조회(TB_FCLT_FAIL_ACT)", response = TbFcltFailActDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbFcltFailActDto> findAll() {
        return this.service.findAll();
    }

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

    @ApiOperation(value = "시설물 장애 발생 조치 정보 목록조회(TB_FCLT_FAIL_ACT)", response = TbFcltFailActDto.class)
    @GetMapping(value = "/{failNo}", produces = {"application/json; charset=utf8"})
    public List<TbFcltFailActDto> findActListByFailNo(@PathVariable("failNo") final String failNo) {
        return this.service.findActListByFailNo(failNo);
    }

    @ApiOperation(value = "시설물 장애 발생 조치 정보 정보변경/생성-개별(TB_FCLT_FAIL_ACT)", response = TbFcltFailActDto.class)
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public TbFcltFailActDto mergeInfo(@RequestBody @Valid final TbFcltFailActDto.TbFcltFailActUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "시설물 장애 발생 조치 정보 정보삭제-개별(TB_FCLT_FAIL_ACT)", response = TbFcltFailActDto.class)
    @DeleteMapping(value = "/{failNo}/{actSeq}", produces = {"application/json; charset=utf8"})
    public TbFcltFailActDto deleteDataById(@PathVariable("failNo") final String failNo, @PathVariable("actSeq") final Integer actSeq) {
        TbFcltFailActKey key = new TbFcltFailActKey(failNo, actSeq);
        return this.service.deleteById(key);
    }

    @ApiOperation(value = "신규 ACT SEQ 조회", response = NewIdLongDto.class)
    @GetMapping(value = "/new-id/act-eeq/{failNo}", produces = {"application/json; charset=utf8"})
    public NewIdLongDto getNewActSeq(@PathVariable("failNo") final String failNo) {
        return this.service.getNewActSeq(failNo);
    }

}
