/**
 * date : 2022. 4. 25.
 * auth : ckr
 * desc : 정산
 */
package kr.co.uplus.ez.api.calculate;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import kr.co.uplus.ez.api.calculate.dto.CalcListExcelReqDto;
import kr.co.uplus.ez.api.calculate.dto.CalcListExcelResDto;
import kr.co.uplus.ez.api.calculate.dto.CalcListReqDto;
import kr.co.uplus.ez.api.calculate.dto.CalcListResDto;
import kr.co.uplus.ez.common.components.ValidComponents;
import kr.co.uplus.ez.common.data.ApiResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@RestController
@RequestMapping(value = "api/v1/bo/calculate")
public class CalculateController {
	@Autowired
	CalculateService calculateService;

	@Autowired
	ValidComponents validComponents;

	/**
	 * date : 2022. 4. 25.
	 * auth : ckr
	 * desc : 정산 이력 목록 조회
	 * @param calcListReqDto
	 * @return
	 */
	@ApiOperation(value = "calcList", notes = "정산 이력 목록 조회")
	@ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_OK, message = "SUCESS") })
	@RequestMapping(value = "/calcList" , method = {RequestMethod.POST})
	@ResponseBody
	public CalcListResDto calcList(@RequestBody @Valid CalcListReqDto calcListReqDto, BindingResult bindingResult) {
		if (validComponents.validParameter(bindingResult)) {
			return new CalcListResDto(ApiResponseCode.CM_PARAMETER_ERROR);
		}
		return calculateService.calcList(calcListReqDto);
	}

	/**
	 * date : 2022. 4. 25.
	 * auth : ckr
	 * desc : 정산 이력 목록 엑셀 다운로드
	 * @param calcListExcelReqDto
	 * @return
	 */
	@RequestMapping(value = "/calcListExcel" , method = {RequestMethod.POST})
	@ResponseBody
	public CalcListExcelResDto calcListExcel(@RequestBody @Valid CalcListExcelReqDto calcListExcelReqDto, BindingResult bindingResult){
		if (validComponents.validParameter(bindingResult)) {
			return new CalcListExcelResDto(ApiResponseCode.CM_PARAMETER_ERROR);
		}
		return calculateService.calcListExcel(calcListExcelReqDto);
	}
}
