package cn.pluss.platform.controller.merchant;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.dto.MerchantRateNewDTO;
import cn.pluss.platform.dto.MerchantRateNewRecordDTO;
import cn.pluss.platform.entity.MerchantRateNewRecord;
import cn.pluss.platform.merchant.MerchantRateNewRecordService;
import cn.pluss.platform.merchant.MerchantRateNewService;
import cn.pluss.platform.vo.MerchantRateNewRecordVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 商户费率相关接口，新
 * @author djh
 */
@RequestMapping("merchantRateNew")
@RestController
public class MerchantRateNewController {

    @Autowired
    private MerchantRateNewService rateNewService;

    @Autowired
    private MerchantRateNewRecordService newRecordService;

    @GetMapping("/rate")
    public Result<Object> rate(String userId) {
        Map<String, Object> rateMap = rateNewService.apiGetRate(userId);
        return ResultGenerator.genSuccessResult(rateMap);
    }

    @PostMapping("/rate")
    public Result<Object> rate(@RequestBody MerchantRateNewDTO params) {
        if (params.getBankRateLargeD0() != null) {
            params.setBankRateLargeD0(new BigDecimal("0.61"));
        }

        if (params.getBankRateLargeD1() != null) {
            params.setBankRateLargeD1(new BigDecimal("0.61"));
        }

        rateNewService.apiChangeMerchantRateNew(params);
        return ResultGenerator.genSuccessResult("费率修改请求已提交", null);
    }


    @GetMapping("/record")
    public Result<Object> rate(Page<MerchantRateNewRecord> page, MerchantRateNewRecordDTO entity) {
        Page<MerchantRateNewRecordVO> result = newRecordService.apiPage(page, entity);
        return ResultGenerator.genSuccessResult("操作成功", result);
    }
}
