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

import com.its.api.its.model.dto.link.LinkParaClctSystDto;
import com.its.api.its.model.entity.link.TbLinkParaClctSyst;
import com.its.api.its.service.link.LinkParaClctSystService;
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 java.util.ArrayList;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/database/link-para-clct-syst")
@Api(tags = "09.기초데이터관리-06.가공파라미터관리-04.링크파라미터수집시스템")
public class LinkParaClctSystController {

    private final LinkParaClctSystService service;

    /*
    @ApiOperation(value = "전체조회(TB_LINK_PARA_CLCT_SYST)", response = LinkParaClctSystDto.LinkParaClctSystInfo.class)
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public ResponseEntity<List<LinkParaClctSystDto.LinkParaClctSystInfo>> findAll() {
        List<LinkParaClctSyst> objList = this.service.findAll();
        List<LinkParaClctSystDto.LinkParaClctSystInfo> result = new ArrayList<>();
        if (objList != null) {
            for (LinkParaClctSyst obj : objList) {
                result.add(new LinkParaClctSystDto.LinkParaClctSystInfo(obj));
            }
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
*/

    @ApiOperation(value = "개별목록조회(TB_LINK_PARA_CLCT_SYST)", response = LinkParaClctSystDto.LinkParaClctSystInfo.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public ResponseEntity<List<LinkParaClctSystDto.LinkParaClctSystInfo>> findById(@PathVariable final Long id) {
        List<TbLinkParaClctSyst> objList = this.service.findListById(id);
        List<LinkParaClctSystDto.LinkParaClctSystInfo> result = new ArrayList<>();
        if (objList != null) {
            for (TbLinkParaClctSyst obj : objList) {
                result.add(new LinkParaClctSystDto.LinkParaClctSystInfo(obj));
            }
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @ApiOperation(value = "개별정보변경/생성(TB_LINK_PARA_CLCT_SYST)", response = LinkParaClctSystDto.LinkParaClctSystUpdateReq.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public ResponseEntity<List<LinkParaClctSystDto.LinkParaClctSystUpdateReq>> updateById(
            @PathVariable final Long id,
            @RequestBody final List<LinkParaClctSystDto.LinkParaClctSystUpdateReq> req) {

        List<LinkParaClctSystDto.LinkParaClctSystUpdateReq> objList = this.service.mergeById(id, req);
        return new ResponseEntity<>(objList, HttpStatus.OK);
    }

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

}
