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

import com.its.api.its.model.dto.link.LinkPrcsParaDto;
import com.its.api.its.service.link.LinkPrcsParaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/database/link-prcs-para")
@Api(tags = "09.기초데이터관리-06.가공파라미터관리-01.가공파라미터관리")
public class LinkPrcsParaController {

    private final LinkPrcsParaService service;

    @ApiOperation(value = "개별정보조회(TB_LINK_PARA_STUP, TB_LINK_PARA_DETL, TB_LINK_PARA_CLCT_SYST)", response = LinkPrcsParaDto.LinkPrcsParaInfo.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public ResponseEntity<LinkPrcsParaDto.LinkPrcsParaInfo> findById(@PathVariable final Long id) {
        LinkPrcsParaDto.LinkPrcsParaInfo result = this.service.findListById(id);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @ApiOperation(value = "개별정보변경/생성(TB_LINK_PARA_STUP, TB_LINK_PARA_DETL, TB_LINK_PARA_CLCT_SYST)", response = LinkPrcsParaDto.LinkPrcsParaUpdateReq.class)
    @PostMapping(value = "/{ids}", produces = {"application/json; charset=utf8"})
    public ResponseEntity<LinkPrcsParaDto.LinkPrcsParaUpdateReq> mergeById(
            @PathVariable final List<Long> ids,
            @RequestBody @Valid final LinkPrcsParaDto.LinkPrcsParaUpdateReq req) {

        log.error("{}, [{}]", ids.size(), ids);
        log.error("{}", req);
        LinkPrcsParaDto.LinkPrcsParaUpdateReq result = this.service.mergeById(ids, req);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @ApiOperation(value = "전체정보변경/생성(TB_LINK_PARA_STUP, TB_LINK_PARA_DETL, TB_LINK_PARA_CLCT_SYST)", response = LinkPrcsParaDto.LinkPrcsParaUpdateReq.class)
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public ResponseEntity<LinkPrcsParaDto.LinkPrcsParaUpdateReq> updateById(@RequestBody final LinkPrcsParaDto.LinkPrcsParaUpdateReq req) {
        LinkPrcsParaDto.LinkPrcsParaUpdateReq result = this.service.mergeAll(req);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

}
