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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.sttlmng.SttlInspectStateService;
import com.oqpo.api.web.dto.request.sttlmng.*;
import com.oqpo.api.web.dto.response.SaveResponse;
import io.swagger.annotations.Api;
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/sttl/inspect/state")
@Api(tags = {"정산검수현황 (SttlInspectStateController)"})
public class SttlInspectStateController {

    @Autowired
    private SttlInspectStateService sttlInspectStateService;

    /**
     * 설명 : 정산확정
     *
     * @param userId
     * @param sttlConfirmRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "정산확정")
    @PostMapping("/sttl-confirm")
    public ResponseEntity<SaveResponse> confirmSttl(@ApiIgnore String userId, @RequestBody @Valid SttlConfirmRequest sttlConfirmRequest) throws Exception {
        sttlInspectStateService.confirmSttl(userId, sttlConfirmRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

    /**
     * 설명 : 정산반려
     *
     * @param userId
     * @param sttlRejectRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "정산반려")
    @PostMapping("/sttl-reject")
    public ResponseEntity<SaveResponse> rejectSttl(@ApiIgnore String userId, @RequestBody @Valid SttlRejectRequest sttlRejectRequest) throws Exception {
        sttlInspectStateService.rejectSttl(userId, sttlRejectRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

}
