package com.xxfc.platform.activity.rest;

import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.xxfc.platform.activity.biz.UserCouponBiz;
import com.xxfc.platform.activity.vo.UserCouponVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserCouponController extends ActivityBaseController<UserCouponBiz> {


    @ApiOperation("用户自动领取新人卷")
    @RequestMapping(value = "/auth/led", method = RequestMethod.POST)
    public String led(@RequestParam(value = "userId",defaultValue = "0") Integer userId) {
        return baseBiz.authledCoupon(userId);
    }

    @ApiOperation("我的优惠卷")
    @RequestMapping(value = "/list/{type}", method = RequestMethod.GET)
    public ObjectRestResponse list(@PathVariable Integer type) {
        AppUserDTO userInfo = getUserInfo();
        Integer userId = userInfo.getId();
        if(userId==null){
            return ObjectRestResponse.createDefaultFail();
        }
        return baseBiz.getCouponList(userId,type);
    }

    @ApiOperation("单个优惠卷信息")
    @RequestMapping(value = "/info/{no}", method = RequestMethod.GET)
    public UserCouponVo info(@PathVariable String no) {
        return baseBiz.getUserCoupon(no);
    }


    @ApiOperation("优惠卷使用")
    @RequestMapping(value = "/use", method = RequestMethod.POST)
    public ObjectRestResponse use(
            @RequestParam(value = "userId",defaultValue ="0" ) Integer userId,
            @RequestParam(value = "TickerNo",defaultValue ="" ) String TickerNo,
            @RequestParam(value = "orderNo",defaultValue ="" ) String orderNo
    ) {
        baseBiz.useTickerNo(userId,TickerNo,orderNo);
        return ObjectRestResponse.succ();
    }

    @ApiOperation("优惠卷取消使用")
    @RequestMapping(value = "/cancelUse", method = RequestMethod.POST)
    public ObjectRestResponse cancelUse(
            @RequestParam(value = "TickerNo",defaultValue ="" ) String TickerNo){
        baseBiz.cancelTickerNo(TickerNo);
        return ObjectRestResponse.succ();
    }



}