package com.its.op.controller.its.vms;

import com.its.op.dto.its.common.NewIdIntegerDto;
import com.its.op.dto.its.common.UsageCountDto;
import com.its.op.dto.its.vms.TbVmsFormDetlDto;
import com.its.op.dto.its.vms.TbVmsFormDto;
import com.its.op.dto.its.vms.TbVmsFormObjectDetlDto;
import com.its.op.service.its.vms.TbVmsFormService;
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 = "12.VMS-2.폼관리-1.문자식/도형식 폼관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/vms/form/manage")
public class TbVmsFormController {

    private final TbVmsFormService service;

    @ApiOperation(value = "VMS FORM 전체조회(TB_VMS_FORM)", response = TbVmsFormDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbVmsFormDto> findAll() {
        return service.findAll();
    }

    @ApiOperation(value = "VMS FORM 유형별 조회(TB_VMS_FORM)", response = TbVmsFormDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/form/{type}", produces = {"application/json; charset=utf8"})
    public List<TbVmsFormDto> findAllByType(
            @ApiParam(name = "type", value = "VMS 크기유형", example = "VMP2", required = true)
            @PathVariable final String type
    ) {
        return service.findAllByTypeSimple(type);
    }

    @ApiOperation(value = "VMS FORM 개별조회(TB_VMS_FORM)", response = TbVmsFormDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsFormDto findById(@PathVariable final Integer id) {
        return this.service.findById(id);
    }

    @ApiOperation(value = "VMS FORM 객체 목록 조회(TB_VMS_FORM)", response = TbVmsFormObjectDetlDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/object/{id}", produces = {"application/json; charset=utf8"})
    public List<TbVmsFormObjectDetlDto> findByVmsFormObject(@PathVariable final Integer id) {
        return this.service.findByVmsFormObject(id);
    }
    @ApiOperation(value = "VMS FORM 객체 목록 상세 조회(TB_VMS_FORM)", response = TbVmsFormDetlDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/form/detail/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsFormDetlDto findByVmsFormObjectDetail(@PathVariable final Integer id) {
        return this.service.findByVmsFormObjectDetail(id);
    }

    @ApiOperation(value = "VMS FORM 정보변경-폼정보만 업데이트(TB_VMS_FORM)", response = TbVmsFormDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsFormDto updateById(@PathVariable final Integer id, @RequestBody @Valid final TbVmsFormDto.TbVmsFormUpdReq req) {
        return this.service.updateById(id, req);
    }

    @ApiOperation(value = "VMS FORM 정보변경/생성/업데이트-개별-객체정보포함(TB_VMS_FORM)", response = TbVmsFormDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsFormDto mergeInfo(@PathVariable("id") Integer id, @RequestBody @Valid final TbVmsFormDto.TbVmsFormUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "VMS FORM 정보삭제-개별(TB_VMS_FORM)", response = TbVmsFormDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbVmsFormDto deleteDataById(@PathVariable("id") Integer id) {
        return this.service.deleteById(id);
    }

    @ApiOperation(value = "신규 VMS FORM ID 조회(TB_VMS_FORM)", response = NewIdIntegerDto.class)
    @GetMapping(value = "/new-id", produces = {"application/json; charset=utf8"})
    public NewIdIntegerDto getNewVmsFormId() {
        return this.service.getNewVmsFormId();
    }

    @ApiOperation(value = "VMS FORM 복사 추가", response = TbVmsFormDto.class)
    @PostMapping(value = "/form/copy-add", produces = {"application/json; charset=utf8"})
    public TbVmsFormDto formCopyAdd(@RequestBody @Valid final TbVmsFormDto.TbVmsFormCopyReq req) {
        return this.service.formCopyAdd(req);
    }

    @ApiOperation(value = "VMS FORM 사용 여부 조회", response = UsageCountDto.class)
    @GetMapping(value = "/usage/{id}", produces = {"application/json; charset=utf8"})
    public UsageCountDto findUsageId(
            @ApiParam(name = "id", value = "폼 ID", example = "10005", required = true)
            @PathVariable final Integer id) {
        return this.service.findUsageId(id);
    }

}
