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

import com.oqpo.api.enums.SystemMessageCode;
import com.oqpo.api.service.loanmng.DsptMngService;
import com.oqpo.api.web.dto.request.loanmng.*;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.SaveResponse;
import com.oqpo.api.web.dto.response.loanmng.DsptMngInfoResponse;
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/dspt/mng")
@Api(tags = {"입금관리 (DsptMngController) -- 완료"})
public class DsptMngController {

    @Autowired
    private DsptMngService dsptMngService;

    /**
     * 설명 : 입금관리 그리드 리스트
     *
     * @param dsptMngGridRequest
     * @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 DsptMngGridRequest dsptMngGridRequest) throws Exception {
        return ResponseEntity.ok(dsptMngService.selectDsptMngGridList(dsptMngGridRequest.getSBrandId(), dsptMngGridRequest.getSStoreId(),
                dsptMngGridRequest.getSDpstStCd(), dsptMngGridRequest.getFromDt(),
                dsptMngGridRequest.getToDt(), dsptMngGridRequest.toDTO(dsptMngGridRequest)));
    }

    /**
     * 설명 : 입금 요청
     *
     * @param userId
     * @param reqDsptRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "입금 요청")
    @PostMapping("/request-dspt")
    public ResponseEntity<SaveResponse> requestDspt(@ApiIgnore String userId, @RequestBody @Valid ReqDsptRequest reqDsptRequest) throws Exception {
        dsptMngService.requestDspt(userId, reqDsptRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

    /**
     * 설명 : 입금 승인
     *
     * @param userId
     * @param approveDsptRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "입금 승인")
    @PostMapping("/approve-dspt")
    public ResponseEntity<SaveResponse> approveDspt(@ApiIgnore String userId, @RequestBody @Valid ApproveDsptRequest approveDsptRequest) throws Exception {
        dsptMngService.approveDspt(userId, approveDsptRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

    /**
     * 설명 : 입금 반려
     *
     * @param userId
     * @param rejectDsptRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "입금 반려")
    @PostMapping("/reject-dspt")
    public ResponseEntity<SaveResponse> rejectDspt(@ApiIgnore String userId, @RequestBody @Valid RejectDsptRequest rejectDsptRequest) throws Exception {
        dsptMngService.rejectDspt(userId, rejectDsptRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

    /**
     * 설명 : 입금 정보
     *
     * @param dsptMgntNo
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "dsptMgntNo", value = "입금아이디", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "입금 정보")
    @GetMapping("/info-dspt")
    public ResponseEntity<DsptMngInfoResponse> infoDspt(@RequestParam(value = "dsptMgntNo") String dsptMgntNo) throws Exception {
        return ResponseEntity.ok(dsptMngService.selectDsptMngInfo(dsptMgntNo));
    }

    /**
     * 설명 : 입금 정보 삭제
     *
     * @param userId
     * @param removeDsptRequest
     * @return SaveResponse
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "입금 삭제")
    @PostMapping("/remove-dspt")
    public ResponseEntity<SaveResponse> removeDspt(@ApiIgnore String userId, @RequestBody @Valid RemoveDsptRequest removeDsptRequest) throws Exception {
        dsptMngService.removeDspt(userId, removeDsptRequest);
        return ResponseEntity.ok(SaveResponse.toDTO(SystemMessageCode.SAVE_OK));
    }

}
