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

import com.its.op.dto.its.common.NewIdStringDto;
import com.its.op.dto.its.common.UsageCountDto;
import com.its.op.dto.its.facility.*;
import com.its.op.service.its.facility.TbFcltFailService;
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.시설물 상태관리-1.시설물 장애등록")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/facility/fail/plan")
public class TbFcltFailController {

    private final TbFcltFailService service;

    @ApiOperation(value = "시설물 장애 진행상태-장애조치 코드 조회", response = FcltFailStepDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/code/fail-step", produces = {"application/json; charset=utf8"})
    public List<FcltFailStepDto> findAllFailStep() {
        return this.service.findAllFailStep();
    }

    @ApiOperation(value = "시설물 장애 등록 코드 조회", response = FcltFailRegDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/code/fail-reg", produces = {"application/json; charset=utf8"})
    public List<FcltFailRegDto> findAllFailReg() {
        return this.service.findAllFailReg();
    }

    @ApiOperation(value = "시설물 장애 등급 코드 조회", response = FcltFailLevlDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/code/fail-levl", produces = {"application/json; charset=utf8"})
    public List<FcltFailLevlDto> findAllFailLevl() {
        return this.service.findAllFailLevl();
    }

    @ApiOperation(value = "시설물 장애 날씨 코드 조회", response = FcltFailWthrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/code/fail-wthr", produces = {"application/json; charset=utf8"})
    public List<FcltFailWthrDto> findAllWthr() {
        return this.service.findAllWthr();
    }

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

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

    @ApiOperation(value = "시설물 장애 현황 조회(완료항목 포함)", response = TbFcltFailDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/all/{fromDay}/{toDay}", produces = {"application/json; charset=utf8"})
    public List<TbFcltFailDto> findAllListByDate(@PathVariable("fromDay") final String fromDay,
                                                 @PathVariable("toDay") final String toDay) {
        return this.service.findAllListByDate(true, fromDay, toDay);
    }

    @ApiOperation(value = "시설물 장애 관리 목록 조회(완료항목제외)", response = TbFcltFailDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list/mng/{fromDay}/{toDay}", produces = {"application/json; charset=utf8"})
    public List<TbFcltFailDto> findRegListByDate(@PathVariable("fromDay") final String fromDay,
                                                 @PathVariable("toDay") final String toDay) {
        return this.service.findAllListByDate(false, fromDay, toDay);
    }

    @ApiOperation(value = "시설물 장애 발생 정보 개별조회(TB_FCLT_FAIL)", response = TbFcltFailDto.class)
    @GetMapping(value = "/{failNo}", produces = {"application/json; charset=utf8"})
    public TbFcltFailDto findById(@PathVariable("failNo") final String failNo) {
        return this.service.findById(failNo);
    }

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

    @ApiOperation(value = "조치내역 존재 여부 조회", response = UsageCountDto.class)
    @GetMapping(value = "/usage/{failNo}", produces = {"application/json; charset=utf8"})
    public UsageCountDto findUsageId(@PathVariable("failNo") final String failNo) {
        return this.service.findUsageId(failNo);
    }

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

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

}
