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

import com.its.api.its.model.dto.oper.TbOperSystDto;
import com.its.api.its.model.dto.oper.TbUserGropInfrDto;
import com.its.api.its.model.dto.oper.TbUserInfrDto;
import com.its.api.its.service.oper.TbOperSystService;
import com.its.api.its.service.oper.TbUserGropInfrService;
import com.its.api.its.service.oper.TbUserInfrService;
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.기초데이터관리-10.운영자관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/database/user-infr")
public class TbUserInfrController {

    private final TbUserInfrService service;
    private final TbUserGropInfrService userGroupInfrService;
    private final TbOperSystService operSystService;

    @ApiOperation(value = "운영자그룹조회(TB_USERGROP_INFR)", response = TbUserGropInfrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/user-grop", produces = {"application/json; charset=utf8"})
    public List<TbUserGropInfrDto> findAllUserGropInfr() {
        return this.userGroupInfrService.findAllUserGropInfr();
    }

    @ApiOperation(value = "운영시스템조회(TB_OPERSYST)", response = TbOperSystDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/oper-syst", produces = {"application/json; charset=utf8"})
    public List<TbOperSystDto> findAllOperSyst() {
        return this.operSystService.findAllOperSyst();
    }

    @ApiOperation(value = "사용자 비밀번호변경(TB_USER_INFR)", response = TbUserInfrDto.class)
    @PutMapping(value = "/pswd/{id}", produces = {"application/json; charset=utf8"})
    public TbUserInfrDto updatePswdById(
            @ApiParam(name = "id", value = "사용자 ID", example = "", required = true)
            @PathVariable("id") String id,
            @RequestBody TbUserInfrDto.TbUserPswdUpdReq req) {
        return this.service.updatePswdById(id, req);
    }

    @ApiOperation(value = "사용자정보 전체조회(TB_USER_INFR)", response = TbUserInfrDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbUserInfrDto> findAll() {
        return service.findAll();
    }

    @ApiOperation(value = "사용자정보 개별조회(TB_USER_INFR)", response = TbUserInfrDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbUserInfrDto findById(@PathVariable final String id) {
        return this.service.findById(id);
    }

    @ApiOperation(value = "사용자정보 정보변경(TB_USER_INFR)", response = TbUserInfrDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbUserInfrDto updateById(@PathVariable final String id, @RequestBody @Valid final TbUserInfrDto.TbUserInfrUpdReq req) {
        return this.service.updateById(id, req);
    }

    @ApiOperation(value = "사용자정보 정보변경/생성-목록(TB_USER_INFR)", response = TbUserInfrDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbUserInfrDto> mergeInfoList(@RequestBody @Valid final List<TbUserInfrDto.TbUserInfrUpdReq> listReq) {
        return this.service.mergeInfoList(listReq);
    }

    @ApiOperation(value = "사용자정보 정보변경/생성-개별(TB_USER_INFR)", response = TbUserInfrDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbUserInfrDto mergeInfo(@PathVariable("id") String id, @RequestBody @Valid final TbUserInfrDto.TbUserInfrUpdReq req) {
        return this.service.mergeInfo(id, req);
    }

    @ApiOperation(value = "사용자정보 정보삭제-개별(TB_USER_INFR)", response = TbUserInfrDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbUserInfrDto deleteDataById(@PathVariable("id") String id) {
        return this.service.deleteById(id);
    }

    @ApiOperation(value = "사용자정보 정보삭제-목록(TB_USER_INFR)", response = TbUserInfrDto.class, responseContainer = "ArrayList")
    @DeleteMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbUserInfrDto> deleteDataByIds(@RequestBody @Valid final List<String> ids) {
        return this.service.deleteByIds(ids);
    }

}
