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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.system.ActionService;
import com.oqpo.api.web.dto.request.act.ActionGridRequest;
import com.oqpo.api.web.dto.request.act.SaveActionRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
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/act")
public class ActionController {
    @Autowired
    private ActionService actionService;

    /**
     * 설명 : 액션 상세 그리드 리스트
     *
     * @param codeGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "액션 상세 그리드 리스트")
    @PostMapping("/detail-grid-list")
    public ResponseEntity<GridResponse> detailGridList(@RequestBody @Valid ActionGridRequest actionGridRequest) throws Exception {
        return ResponseEntity.ok(actionService.actDtlGridList(actionGridRequest.getMenuNo(), actionGridRequest.toDTO(actionGridRequest)));
    }

    /**
     * 설명 : 액션 정보 저장
     *
     * @param userId
     * @param saveActionRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "액션정보 저장")
    @PostMapping("/save-action")
    public ResponseEntity<SaveResponse> saveAction(@ApiIgnore String userId, @RequestBody @Valid SaveActionRequest saveActionRequest) throws Exception {
        actionService.saveAction(userId, saveActionRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }


}
