package com.neusoft.smart.pos.trade.controller;


import com.neusoft.smart.pos.dto.trade.request.PostBillSettlementCycleRequest;
import com.neusoft.smart.pos.dto.trade.request.PutBillSettlementCycleRequest;
import com.neusoft.smart.pos.dto.trade.response.GetBillSettlementCycleResponse;
import com.neusoft.smart.pos.dto.trade.response.PostBillSettlementCycleResponse;
import com.neusoft.smart.pos.dto.trade.response.PutBillSettlementCycleResponse;
import com.neusoft.smart.pos.framework.constants.CommonErrorCode;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.framework.exception.BusinessCommonException;
import com.neusoft.smart.pos.trade.service.BillSettlementCycleService;
import com.neusoft.smart.pos.utils.RequestHeaderUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(value = "商户结算周期信息管理使用rest接口", description = "商户结算周期信息管理使用rest接口")
@RestController
@Validated
@RequestMapping(path = "/billSettlementCycle")
public class BillSettlementCycleController {

	@Autowired
	private BillSettlementCycleService billSettlementCycleService;

	@ApiOperation(value = "结算周期查询使用接口", notes = "未使用gateway")
	@GetMapping("/billSettlementCycle")
	public ResponseData<GetBillSettlementCycleResponse> queryBillSettlementCycle() {
		Integer orgId = RequestHeaderUtil.getOrgId();
		if (null == orgId) {
			throw new BusinessCommonException(CommonErrorCode.PERMISSION_ERROR);
		}
		return new ResponseData<>(billSettlementCycleService.queryBillSettlementCycle(orgId));
	}
	
	@ApiOperation(value = "结算周期信息新增使用接口", notes = "未使用gateway")
	@PostMapping("/billSettlementCycle")
	public ResponseData<PostBillSettlementCycleResponse> saveBillSettlementCycle(@Valid @RequestBody PostBillSettlementCycleRequest billSettlementCycleRequest, BindingResult bindingResult) {
		Integer orgId = RequestHeaderUtil.getOrgId();
		if (null == orgId) {
			throw new BusinessCommonException(CommonErrorCode.PERMISSION_ERROR);
		}
		return new ResponseData<>(billSettlementCycleService.saveBillSettlementCycle(orgId,billSettlementCycleRequest));
	}
    
    @ApiOperation(value = "结算周期信息更新使用接口", notes = "未使用gateway")
    @PutMapping("/billSettlementCycle")
    public ResponseData<PutBillSettlementCycleResponse> updateBillSettlementCycle(@Valid @RequestBody PutBillSettlementCycleRequest billSettlementCycleRequest, BindingResult bindingResult) {
        Integer orgId = RequestHeaderUtil.getOrgId();
        if (null == orgId) {
            throw new BusinessCommonException(CommonErrorCode.PERMISSION_ERROR);
        }
        return new ResponseData<>(billSettlementCycleService.updateBillSettlementCycle(orgId,billSettlementCycleRequest));
    }
}

