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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.sttlmng.SttlStateService;
import com.oqpo.api.web.dto.request.sttlmng.SttlConfirmRequest;
import com.oqpo.api.web.dto.request.sttlmng.SttlStateGridRequest;
import com.oqpo.api.web.dto.response.GridResponse;
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/state")
@Api(tags = {"정산현황 (SttlStateController)"})
public class SttlStateController {

    @Autowired
    private SttlStateService sttlStateService;

    /**
     * 설명 : 정산현황 그리드 리스트
     *
     * @param sttlStateGridRequest
     * @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 SttlStateGridRequest sttlStateGridRequest) throws Exception {
        return ResponseEntity.ok(sttlStateService.selectSttlStateGridList(sttlStateGridRequest.getSGubun(), sttlStateGridRequest.getSBrandId(), sttlStateGridRequest.getSStoreId(),
                sttlStateGridRequest.getSSpplyId(), sttlStateGridRequest.getSItemNm(), sttlStateGridRequest.getSSttlStCd(),
                sttlStateGridRequest.getFromDt(), sttlStateGridRequest.getToDt(), sttlStateGridRequest.getPageType(), sttlStateGridRequest.toDTO(sttlStateGridRequest)));
    }

    /**
     * 설명 : 정산완료
     *
     * @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-end")
    public ResponseEntity<SaveResponse> confirmSttl(@ApiIgnore String userId, @RequestBody @Valid SttlConfirmRequest sttlConfirmRequest) throws Exception {
        sttlStateService.endSttl(userId, sttlConfirmRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

}
