package com.its.op.controller.its.database;

import com.its.op.dto.its.node.TbNodeDto;
import com.its.op.service.its.node.TbNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.기초데이터관리-01.노드")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/database/node")
public class TbNodeController {

    private final TbNodeService service;

    @ApiOperation(value = "노드정보 전체조회(TB_NODE)", response = TbNodeDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list", produces = {"application/json; charset=utf8"})
    public List<TbNodeDto> findAll() {
        return service.findAll();
    }

    @ApiOperation(value = "노드정보 개별조회(TB_NODE)", response = TbNodeDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbNodeDto findById(@PathVariable final Long id) {
        return this.service.findById(id);
    }

/*
    @ApiOperation(value = "노드정보 정보변경(TB_NODE)", response = TbNodeDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbNodeDto updateById(@PathVariable final Long id, @RequestBody @Valid final TbNodeDto.TbNodeUpdReq req) {
        return this.service.updateById(id, req);
    }
*/

    @ApiOperation(value = "노드정보 노드이름변경(TB_NODE)", response = TbNodeDto.class)
    @PutMapping(value = "/name/{id}", produces = {"application/json; charset=utf8"})
    public TbNodeDto updateNameById(@PathVariable final Long id, @RequestBody @Valid final TbNodeDto.TbNodeNameUpdReq req) {
        return this.service.updateNameById(id, req);
    }

}
