package com.its.op.controller.its.database;

import com.its.op.dto.its.database.TbHldyInfrDto;
import com.its.op.service.its.code.TbCmmnCdService;
import com.its.op.service.its.database.TbLeglHldyInfrService;
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 = "09.기초데이터관리-08.휴일관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/database/legl-hldy-infr")
public class TbLeglHldyInfrController {

    private final TbLeglHldyInfrService service;
    private final TbCmmnCdService cmmnCdService;

    @ApiOperation(value = "휴일코드조회(TB_CMMN_CD)", response = TbHldyInfrDto.LeglHldyType.class, responseContainer = "ArrayList")
    @GetMapping(value = "/hldy-type", produces = {"application/json; charset=utf8"})
    public List<TbHldyInfrDto.LeglHldyType> findAllHldyType() {
        return this.service.findAllByLeglHldyType();
    }

    @ApiOperation(value = "공휴일 정보 전체조회(TB_LEGL_HLDY_INFR)", response = TbHldyInfrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbHldyInfrDto> findAll() {
        return service.findAll();
    }

    @ApiOperation(value = "공휴일 정보 개별조회(TB_LEGL_HLDY_INFR)", response = TbHldyInfrDto.class)
    @GetMapping(value = "/{day}", produces = {"application/json; charset=utf8"})
    public TbHldyInfrDto findById(
            @ApiParam(name = "day", value = "일자(YYYYMMDD)", example = "20210101", required = true)
            @PathVariable final String day) {
        return this.service.findById(day);
    }

    @ApiOperation(value = "공휴일 정보 정보변경(TB_LEGL_HLDY_INFR)", response = TbHldyInfrDto.class)
    @PutMapping(value = "/{day}", produces = {"application/json; charset=utf8"})
    public TbHldyInfrDto updateById(
            @ApiParam(name = "day", value = "일자(YYYYMMDD'", example = "20210101", required = true)
            @PathVariable final String day, @RequestBody @Valid final TbHldyInfrDto.TbLeglHldyInfrUpdReq req) {
        return this.service.updateById(day, req);
    }

    @ApiOperation(value = "공휴일 정보 정보변경/생성-목록(TB_LEGL_HLDY_INFR)", response = TbHldyInfrDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbHldyInfrDto> mergeInfoList(
            @RequestBody @Valid final List<TbHldyInfrDto.TbLeglHldyInfrUpdReq> listReq) {
        return this.service.mergeInfoList(listReq);
    }

    @ApiOperation(value = "공휴일 정보 정보변경/생성-개별(TB_LEGL_HLDY_INFR)", response = TbHldyInfrDto.class)
    @PostMapping(value = "/{day}", produces = {"application/json; charset=utf8"})
    public TbHldyInfrDto mergeInfo(
            @PathVariable("day") String day,
            @RequestBody @Valid final TbHldyInfrDto.TbLeglHldyInfrUpdReq req) {
        return this.service.mergeInfo(day, req);
    }

    @ApiOperation(value = "공휴일 정보 정보삭제-개별(TB_LEGL_HLDY_INFR)", response = TbHldyInfrDto.class)
    @DeleteMapping(value = "/{day}", produces = {"application/json; charset=utf8"})
    public TbHldyInfrDto deleteDataById(
            @PathVariable("day") String day) {
        return this.service.deleteById(day);
    }

    @ApiOperation(value = "공휴일 정보 정보삭제-목록(TB_LEGL_HLDY_INFR)", response = TbHldyInfrDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbHldyInfrDto> deleteDataByIds(
            @RequestBody @Valid final List<String> days) {
        return this.service.deleteByIds(days);
    }

}
