package com.ruoyi.cai.controller.app;

import com.ruoyi.cai.domain.RechargeOrder;
import com.ruoyi.cai.domain.VipOrder;
import com.ruoyi.cai.dto.ConsumeResp;
import com.ruoyi.cai.dto.app.query.GiveGiftRes;
import com.ruoyi.cai.dto.app.query.GiveGuardReq;
import com.ruoyi.cai.dto.app.query.order.AddRechargeOrderDto;
import com.ruoyi.cai.dto.app.query.order.AddVipOrderDto;
import com.ruoyi.cai.dto.app.vo.order.OrderCreateVo;
import com.ruoyi.cai.manager.ConsumerManager;
import com.ruoyi.cai.service.RechargeOrderService;
import com.ruoyi.cai.service.VipOrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/consume")
@Tag(name = "消费相关的接口")
public class ConsumeController {

    @Autowired
    private ConsumerManager consumerManager;
    @Autowired
    private RechargeOrderService rechargeOrderService;
    @Autowired
    private VipOrderService vipOrderService;

    @PostMapping("/give/guard")
    @Operation(summary = "赠送主播守护")
    @Log(title = "赠送主播守护", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<Boolean> giveGuard(@RequestBody GiveGuardReq query){
        ConsumeResp resp = consumerManager.sendGuard(query);
        return R.ok(resp.isSuccess());
    }

    @PostMapping("/give/gift")
    @Operation(summary = "赠送主播礼物")
    @Log(title = "赠送主播礼物", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<Boolean> giveGift(@RequestBody GiveGiftRes query){
        ConsumeResp resp = consumerManager.sendGift(query);
        return R.ok(resp.isSuccess());
    }

    @PostMapping("/order/vip/create")
    @Operation(summary = "创建VIP订单")
    @Log(title = "创建VIP订单", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<OrderCreateVo> vipOrderCreate(@RequestBody AddRechargeOrderDto dto){
        RechargeOrder order = rechargeOrderService.addRechargeOrder(dto);
        OrderCreateVo vo = new OrderCreateVo();
        vo.setPrice(order.getPrice());
        vo.setOrderNo(order.getOrderNo());
        vo.setOrderName(order.getRechargeName());
        return R.ok(vo);
    }


    @PostMapping("/order/recharge/create")
    @Operation(summary = "创建充值订单")
    @Log(title = "创建充值订单", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<OrderCreateVo> giveGift(@RequestBody AddVipOrderDto dto){
        VipOrder order = vipOrderService.addVipOrder(dto);
        OrderCreateVo vo = new OrderCreateVo();
        vo.setPrice(order.getPrice());
        vo.setOrderNo(order.getOrderNo());
        vo.setOrderName(order.getVipName());
        return R.ok(vo);
    }
}
