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

import com.oqpo.api.service.loanmng.LoanStateService;
import com.oqpo.api.web.dto.request.loanmng.LoanHistGridRequest;
import com.oqpo.api.web.dto.request.loanmng.LoanStateGridRequest;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.loanmng.LoanMngInfoResponse;
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 javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/loan/state")
public class LoanStateController {

    @Autowired
    private LoanStateService loanStateService;

    /**
     * 설명 : 여신현황 그리드 리스트
     *
     * @param loanStateGridRequest
     * @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 LoanStateGridRequest loanStateGridRequest) throws Exception {
        return ResponseEntity.ok(loanStateService.selectLoanStateGridList(loanStateGridRequest.getSBrandId(), loanStateGridRequest.getSStoreId(),
                loanStateGridRequest.getSLoanDvsn(), loanStateGridRequest.getSUseYn(), loanStateGridRequest.toDTO(loanStateGridRequest)));
    }

    /**
     * 설명 : 여신관리 정보
     *
     * @param loanMgntUnqNo
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "loanMgntUnqNo", value = "여신관리고유번호", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "여신관리 정보")
    @GetMapping("/info-loan-mng")
    public ResponseEntity<LoanMngInfoResponse> infoWhs(@RequestParam(value = "loanMgntUnqNo") String loanMgntUnqNo) throws Exception {
        return ResponseEntity.ok(loanStateService.selectLoanMngInfo(loanMgntUnqNo));
    }

    /**
     * 설명 : 여신이력 그리드 리스트
     *
     * @param loanHistGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "여신이력 그리드 리스트")
    @PostMapping("/hist-grid-list")
    public ResponseEntity<GridResponse> histGridList(@RequestBody @Valid LoanHistGridRequest loanHistGridRequest) throws Exception {
        return ResponseEntity.ok(loanStateService.selectLoanHistGridList(loanHistGridRequest.getSLoanMgntUnqNo(), loanHistGridRequest.getSDpstPayDvsn(),
                loanHistGridRequest.getFromDt(), loanHistGridRequest.getToDt(),
                loanHistGridRequest.toDTO(loanHistGridRequest)));
    }

}
