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

import com.oqpo.api.service.loanmng.UnpaidMngService;
import com.oqpo.api.web.dto.request.loanmng.*;
import com.oqpo.api.web.dto.response.GridResponse;
import com.oqpo.api.web.dto.response.loanmng.UnpaidMngInfoResponse;
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 javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/unpaid/mng")
@Api(tags = {"미납금관리 (UnpaidMngController) -- 완료"})
public class UnpaidMngController {

    @Autowired
    private UnpaidMngService unpaidMngService;

    /**
     * 설명 : 미납금관리 그리드 리스트
     *
     * @param unpaidMngGridRequest
     * @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 UnpaidMngGridRequest unpaidMngGridRequest) throws Exception {
        return ResponseEntity.ok(unpaidMngService.selectUnpaidMngGridList(unpaidMngGridRequest.getSBrandId(), unpaidMngGridRequest.getSStoreId(),
                unpaidMngGridRequest.getFromDt(), unpaidMngGridRequest.getToDt(), unpaidMngGridRequest.toDTO(unpaidMngGridRequest)));
    }

    /**
     * 설명 : 미납금 정보
     *
     * @param sttlMgntUnqNo
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "sttlMgntUnqNo", value = "정산관리고유번호", required = true, dataType = "String", paramType = "query")
    })
    @ApiOperation(value = "미납금 정보")
    @GetMapping("/info-unpaid")
    public ResponseEntity<UnpaidMngInfoResponse> infoUnpaid(@RequestParam(value = "sttlMgntUnqNo") String sttlMgntUnqNo) throws Exception {
        return ResponseEntity.ok(unpaidMngService.selectUnpaidMngInfo(sttlMgntUnqNo));
    }

    /**
     * 설명 : 정산대상내역 그리드 리스트
     *
     * @param stlDtlGridRequest
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-AUTH-TOKEN", value = "CONN-KEY", required = true, dataType = "String", paramType = "header")
    })
    @ApiOperation(value = "정산대상내역 그리드 리스트")
    @PostMapping("/stl-grid-list")
    public ResponseEntity<GridResponse> stlGridList(@RequestBody @Valid StlDtlGridRequest stlDtlGridRequest) throws Exception {
        return ResponseEntity.ok(unpaidMngService.selectStlDtlGridList(stlDtlGridRequest.getSttlMgntUnqNo(), stlDtlGridRequest.toDTO(stlDtlGridRequest)));
    }

}
