package com.its.api.its.controller.database;

import com.its.api.its.model.dto.database.TbLeglHldyInfrDto;
import com.its.api.its.service.code.TbCmmnCdService;
import com.its.api.its.service.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 = TbLeglHldyInfrDto.LeglHldyType.class, responseContainer = "ArrayList")
    @GetMapping(value = "/hldy-type", produces = {"application/json; charset=utf8"})
    public List<TbLeglHldyInfrDto.LeglHldyType> findAllHldyType() {
        return this.service.findAllByLeglHldyType();
    }

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

    @ApiOperation(value = "공휴일 정보 개별조회(TB_LEGL_HLDY_INFR)", response = TbLeglHldyInfrDto.class)
    @GetMapping(value = "/{day}", produces = {"application/json; charset=utf8"})
    public TbLeglHldyInfrDto 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 = TbLeglHldyInfrDto.class)
    @PutMapping(value = "/{day}", produces = {"application/json; charset=utf8"})
    public TbLeglHldyInfrDto updateById(
            @ApiParam(name = "day", value = "일자(YYYYMMDD'", example = "20210101", required = true)
            @PathVariable final String day, @RequestBody @Valid final TbLeglHldyInfrDto.TbLeglHldyInfrUpdReq req) {
        return this.service.updateById(day, req);
    }

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

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

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

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

}
