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

import com.its.api.its.model.entity.link.TbLinkParaStup;
import com.its.api.its.model.dto.link.LinkParaStupDto;
import com.its.api.its.service.link.LinkParaStupService;
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.*;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/database/link-para-stup")
@Api(tags = "09.기초데이터관리-06.가공파라미터관리-02.링크파라미터설정")
public class LinkParaStupController {

    private final LinkParaStupService service;

    /*
    @ApiOperation(value = "전체조회(TB_LINK_PARA_STUP)", response = LinkParaStupDto.LinkParaStupInfo.class)
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public ResponseEntity<List<LinkParaStupDto.LinkParaStupInfo>> findAll() {
        List<LinkParaStup> data = this.service.findAll();
        List<LinkParaStupDto.LinkParaStupInfo> result = new ArrayList<>();
        for (LinkParaStup obj: data) {
            result.add(new LinkParaStupDto.LinkParaStupInfo(obj));
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
*/

    @ApiOperation(value = "개별조회(TB_LINK_PARA_STUP)", response = LinkParaStupDto.LinkParaStupInfo.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public ResponseEntity<LinkParaStupDto.LinkParaStupInfo> findById(@PathVariable final Long id) {
        TbLinkParaStup obj = this.service.findById(id);
        if (obj != null) {
            return new ResponseEntity<>(new LinkParaStupDto.LinkParaStupInfo(obj), HttpStatus.OK);
        }
        return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);//NO_CONTENT);
    }

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

        TbLinkParaStup obj = this.service.mergeById(id, req);
        if (obj != null) {
            return new ResponseEntity<>(new LinkParaStupDto.LinkParaStupInfo(obj), HttpStatus.OK);
        }
        return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);//NO_CONTENT);
    }

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

    }

}
