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

import com.its.api.its.model.dto.database.TbCnctIntnDto;
import com.its.api.its.service.database.TbCnctIntnService;
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.기초데이터관리-12.연계기관관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/database/cnct-intn")
public class TbCnctIntnController {

    private final TbCnctIntnService service;

    @ApiOperation(value = "연계기관유형(TB_CMMN_CD)", response = TbCnctIntnDto.TbCnctType.class, responseContainer = "ArrayList")
    @GetMapping(value = "/cnct-type", produces = {"application/json; charset=utf8"})
    public List<TbCnctIntnDto.TbCnctType> findAllHldyType() {
        return this.service.findAllByCnctIntnType();
    }

    @ApiOperation(value = "연계 기관 전체조회(TB_CNCT_INTN)", response = TbCnctIntnDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbCnctIntnDto> findAll() {
        return service.findAll();
    }

    @ApiOperation(value = "연계 기관 개별조회(TB_CNCT_INTN)", response = TbCnctIntnDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbCnctIntnDto findById(
            @ApiParam(name = "id", value = "연계기관 ID", example="1", required = true)
            @PathVariable final Long id) {
        return this.service.findById(id);
    }

    @ApiOperation(value = "연계 기관 정보변경(TB_CNCT_INTN)", response = TbCnctIntnDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbCnctIntnDto updateById(
            @ApiParam(name = "id", value = "연계기관 ID", example="1", required = true)
            @PathVariable final Long id, @RequestBody @Valid final TbCnctIntnDto.TbCnctIntnUpdReq req) {
        return this.service.updateById(id, req);
    }

    @ApiOperation(value = "연계 기관 정보변경/생성-목록(TB_CNCT_INTN)", response = TbCnctIntnDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbCnctIntnDto> mergeInfoList(
            @ApiParam(name = "listReq", value = "연계기관 정보 목록", required = true)
            @RequestBody @Valid final List<TbCnctIntnDto.TbCnctIntnUpdReq> listReq) {
        return this.service.mergeInfoList(listReq);
    }

    @ApiOperation(value = "연계 기관 정보변경/생성-개별(TB_CNCT_INTN)", response = TbCnctIntnDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbCnctIntnDto mergeInfo(
            @ApiParam(name = "id", value = "연계기관 ID", example="1", required = true)
            @PathVariable("id") Long id, @RequestBody @Valid final TbCnctIntnDto.TbCnctIntnUpdReq req) {
        return this.service.mergeInfo(req);
    }

    @ApiOperation(value = "연계 기관 정보삭제-개별(TB_CNCT_INTN)", response = TbCnctIntnDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbCnctIntnDto deleteDataById(
            @ApiParam(name = "id", value = "연계기관 ID", example="1", required = true)
            @PathVariable("id") Long id) {
        return this.service.deleteById(id);
    }

    @ApiOperation(value = "연계 기관 정보삭제-목록(TB_CNCT_INTN)", response = TbCnctIntnDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbCnctIntnDto> deleteDataByIds(
            @ApiParam(name = "ids", value = "연계기관 ID 목록", required = true)
            @RequestBody @Valid final List<Long> ids) {
        return this.service.deleteByIds(ids);
    }

}
