package com.cpop.jambox.business.controller.mini;

import com.cpop.core.base.R;
import com.cpop.jambox.business.bo.LearnNowPayLaterServiceOrderBo;
import com.cpop.jambox.business.bo.LearnNowPayLaterStopUserSignPlansBo;
import com.cpop.jambox.business.bo.LearnNowPayLaterUserSignPlansBo;
import com.cpop.jambox.business.service.CardTemplateService;
import com.cpop.jambox.business.service.EasyLearnOrderService;
import com.cpop.jambox.business.vo.LearnNowPayLaterPlanVo;
import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreSignPlanResult;
import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreUserSignPlanResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author DB
 * @version 1.0.0
 * @since 2024-01-18 22:58
 */
@RestController
@Api(tags = "果酱小程序-放心学接口")
@RequestMapping("/mini/easyLearn")
public class MiniEasyLearnController {

    @Autowired
    private CardTemplateService cardTemplateService;

    @Autowired
    private EasyLearnOrderService easyLearnOrderService;

    /**
     * 获取支付分计划
     * @author DB
     * @since 2024/1/18
     * @param oldTemplateId 旧模板id
     * @param isMonth 是否月付
     * @return R<LearnNowPayLaterPlanDetailVo>
     */
    @ApiOperation("获取支付分计划")
    @GetMapping("/getWxPayScorePlan")
    public R<LearnNowPayLaterPlanVo> getWxPayScorePlan(@ApiParam(value = "旧模板id") @RequestParam(value = "oldTemplateId", required = false) String oldTemplateId,
                                                       @ApiParam(value = "模板id") @RequestParam(value = "templateId", required = false) String templateId,
                                                       @ApiParam(value = "是否月付(0否1是)", required = true) @RequestParam("isMonth") Boolean isMonth) {
        LearnNowPayLaterPlanVo vo = cardTemplateService.getWxPayScorePlan(oldTemplateId, templateId, isMonth);
        return R.ok(vo);
    }

    /**
     * 获取支付分计划
     *
     * @param bo 请求参数
     * @return R<LearnNowPayLaterPlanDetailVo>
     * @author DB
     * @since 2024/1/18
     */
    @ApiOperation("创建用户签约计划")
    @PostMapping("/createUserSignPlans")
    public R<WxPartnerPayScoreUserSignPlanResult> createUserSignPlans(@RequestBody @Validated LearnNowPayLaterUserSignPlansBo bo) {
        WxPartnerPayScoreUserSignPlanResult result = easyLearnOrderService.createUserSignPlans(bo);
        return R.ok(result);
    }

    /**
     * 创建用户服务订单(核销)
     * @author DB
     * @since 2024/1/20
     * @param bo 请求参数
     */
    @ApiOperation("创建用户服务订单(核销)")
    @PostMapping("/createServiceOrder")
    public R<WxPartnerPayScoreSignPlanResult> createServiceOrder(@RequestBody @Validated LearnNowPayLaterServiceOrderBo bo) {
        WxPartnerPayScoreSignPlanResult result = easyLearnOrderService.createServiceOrder(bo);
        return R.ok(result);
    }

    /**
     * 取消用户签约计划
     * @author DB
     * @since 2024/1/20
     * @param bo 请求参数
     * @return R<Void>
     */
    @ApiOperation("取消用户签约计划")
    @PostMapping("/stopUserSignPlans")
    public R<Void> stopUserSignPlans(@RequestBody @Validated LearnNowPayLaterStopUserSignPlansBo bo){
       easyLearnOrderService.stopUserSignPlans(bo);
        return R.ok();
    }

    /**
     * 发送数币手机验证码
     * @author DB
     * @since 2024/1/29
     * @param phone 手机
     * @return R<Void>
     */
    @ApiOperation("发送数币手机验证码")
    @GetMapping("/sendEcppMsmCode/{phone}")
    public R<Void> sendEcppMsmCode(@PathVariable String phone) {
        easyLearnOrderService.sendEcppMsmCode(phone);
        return R.ok();
    }
}
