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

import com.its.op.dto.its.unit.TbUnitSystDto;
import com.its.op.service.its.unit.TbUnitSystService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.기초데이터관리-11.프로세스관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/database/unit-syst")
public class TbUnitSystController {

    private final TbUnitSystService service;

    @ApiOperation(value = "단위 시스템 전체조회(TB_UNIT_SYST)", response = TbUnitSystDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbUnitSystDto> findAll() {
        return service.findAllUnitSystList();
    }

    @ApiOperation(value = "단위 시스템 개별조회(TB_UNIT_SYST)", response = TbUnitSystDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbUnitSystDto findById(
            @ApiParam(name = "id", value = "단위 시스템 ID", example = "OPER01", required = true)
            @PathVariable final String id) {
        return this.service.findById(id);
    }

    @ApiOperation(value = "단위 시스템 정보변경/생성-개별(TB_UNIT_SYST)", response = TbUnitSystDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbUnitSystDto mergeInfo(@PathVariable("id") String id, @RequestBody @Valid final TbUnitSystDto.TbUnitSystUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "단위 시스템 정보삭제-개별(TB_UNIT_SYST)", response = TbUnitSystDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbUnitSystDto deleteDataById(@PathVariable("id") String id) {
        return this.service.deleteById(id);
    }

}
