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

import com.its.api.its.service.link.LinkParaDetlService;
import com.its.api.its.model.dto.link.LinkParaDetlDto;
import com.its.api.its.model.entity.link.TbLinkParaDetl;
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-detl")
@Api(tags = "09.기초데이터관리-06.가공파라미터관리-03.링크파라미터상세")
public class LinkParaDetlController {

    private final LinkParaDetlService service;

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

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

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

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

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

}
