package com.ruoyi.cai.controller.test;

import com.ruoyi.cai.domain.RechargeOrder;
import com.ruoyi.cai.domain.VipOrder;
import com.ruoyi.cai.dto.app.query.order.AddRechargeOrderDto;
import com.ruoyi.cai.dto.app.query.order.AddVipOrderDto;
import com.ruoyi.cai.pay.PayManager;
import com.ruoyi.cai.service.RechargeOrderService;
import com.ruoyi.cai.service.VipOrderService;
import com.ruoyi.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cai/test/pay")
@Tag(name = "测试接口，正式环境取消")
public class TestPayController {

    @Autowired
    private VipOrderService vipOrderService;
    @Autowired
    private RechargeOrderService rechargeOrderService;
    @Autowired
    private PayManager payManager;

    @GetMapping("/vip")
    @Operation(hidden = true)
    public R<Void> vip(Long memberPriceId, Long userId){
        AddVipOrderDto addVipOrderDto = new AddVipOrderDto();
        addVipOrderDto.setUserId(userId);
        addVipOrderDto.setMemberPriceId(memberPriceId);
        VipOrder vipOrder = vipOrderService.addVipOrder(addVipOrderDto);
        payManager.callBack(vipOrder.getOrderNo());
        return R.ok();
    }

    @GetMapping("/recharge")
    @Operation(hidden = true)
    public R<Void> recharge(Long goodId, Long userId){
        AddRechargeOrderDto dto = new AddRechargeOrderDto();
        dto.setUserId(userId);
        dto.setGoodId(goodId);
        RechargeOrder order = rechargeOrderService.addRechargeOrder(dto);
        payManager.callBack(order.getOrderNo());
        return R.ok();
    }
}
