package com.oqpo.api.web.controller.system;

import com.oqpo.api.enums.DataMessageCode;
import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.system.MenuService;
import com.oqpo.api.service.system.NumbService;
import com.oqpo.api.web.dto.request.menu.SaveMenuRequest;
import com.oqpo.api.web.dto.request.numb.SaveNumbRequest;
import com.oqpo.api.web.dto.response.DataResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.code.CodeSearchListResponse;
import com.oqpo.api.web.dto.response.menu.MenuInfoResponse;
import com.oqpo.api.web.dto.response.menu.MenuSearchListResponse;
import com.oqpo.api.web.dto.response.numb.NumbResponse;
import com.oqpo.api.web.dto.response.numb.NumbSearchListResponse;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/numb")
public class NumbController {

    @Autowired
    private NumbService numbService;

    /**
     * 설명 : 채번 검색
     *
     * @param sNumNm
     * @param sUseYn
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "sNumNm", value = "채번명/예약어", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "sUseYn", value = "사용여부", required = false, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "채번 검색")
    @GetMapping("/numb-search")
    public ResponseEntity<NumbSearchListResponse> selectSearchNumbList(@RequestParam(value = "sNumNm", required = false) String sNumNm,
                                                                 @RequestParam(value = "sUseYn", required = false) String sUseYn) throws Exception {
        return ResponseEntity.ok(numbService.selectSearchNumbList(sUseYn, sNumNm));
    }

    /**
     * 설명 : 채번 정보
     *
     * @param numNo
     * @return NumbResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "numNo", value = "채번번호", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "채번 정보")
    @GetMapping("/info-numb")
    public ResponseEntity<NumbResponse> infoNumb(@RequestParam(value = "numNo") String numNo) throws Exception {
        return ResponseEntity.ok(numbService.selectNumbInfo(numNo));
    }

    /**
     * 설명 : 채번정보 저장
     *
     * @param userId
     * @param saveNumbRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "채번정보 저장")
    @PostMapping("/save-numb")
    public ResponseEntity<SaveResponse> saveMenu(@ApiIgnore String userId, @RequestBody @Valid SaveNumbRequest saveNumbRequest) throws Exception {
        numbService.saveNumb(userId, saveNumbRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }


}
