package com.buy507.mall.portal.controller;

import com.buy507.mall.common.api.CommonResult;
import com.buy507.mall.model.OmsOrder;
import com.buy507.mall.portal.domain.OrderParam;
import com.buy507.mall.portal.service.VipCenterService;
import com.buy507.mall.portal.vo.OmsOrderDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/vip")
public class VipController {

    @Autowired
    private VipCenterService vipCenterService;

    @ApiOperation("查询升级权限金额")
    @RequestMapping(value = "/getUpgradeAmount", method = RequestMethod.GET)
    public CommonResult<BigDecimal> getUpgradeAmount(@RequestParam Long memberLevelId){
        BigDecimal amount = vipCenterService.getUpgradeAmount(memberLevelId);
        return CommonResult.success(amount);
    }

    @ApiOperation("创建购买权益订单")
    @RequestMapping(value = "/createUpgradeOrder", method = RequestMethod.POST)
    public CommonResult createUpgradeOrder(@RequestBody OmsOrderDTO param){
        try {
            return vipCenterService.createUpgradeOrder(param);
        } catch (Exception e) {
            return CommonResult.failed("createOrder fail");
        }
    }
}
