package cn.com.ty.lift.ud.userCoupon.controller;

import java.math.BigDecimal;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
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;

import com.baomidou.mybatisplus.extension.service.IService;

import cn.com.ty.lift.ud.common.BaseController;
import cn.com.ty.lift.ud.coupon.service.ICouponService;
import cn.com.ty.lift.ud.userCoupon.controller.query.UserCouponQuery;
import cn.com.ty.lift.ud.userCoupon.mapper.entity.CouponNumResp;
import cn.com.ty.lift.ud.userCoupon.mapper.entity.UserCoupon;
import cn.com.ty.lift.ud.userCoupon.service.IUserCouponService;
import cn.com.xwy.boot.web.dto.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户卡券 API
 * 
 * @author Xson
 * @date 2020-05-12
 */
@Api(tags = "用户卡券 API -魏瑞锋")
@RestController
@RequestMapping("/api/userCoupons")
public class UserCouponController extends BaseController<UserCoupon, UserCouponQuery> {

    private final Logger log = LoggerFactory.getLogger(UserCouponController.class);

    private @Autowired IUserCouponService userCouponService;
    private @Autowired ICouponService couponService;

    @Override
    protected IService<UserCoupon> getService() {
        return userCouponService;
    }

    // 根据条件查询
    @PostMapping("/query-page")
    @ApiOperation(value = "分页查询")
    public RestResponse getCondition(@RequestBody UserCouponQuery request) {
        return userCouponService.selectByExample(request);
    }

    @PostMapping("/couponNum")
    @ApiOperation(value = "我的卡券红包余额")
    public RestResponse getCouponNum(Long userId) {
        CouponNumResp couponNum = userCouponService.getCouponNum(userId);
        return RestResponse.success(couponNum, "Queried successfully");
    }

    @GetMapping("/queryAll")
    @ApiOperation(value = "查询所有")
    public RestResponse queryAll(Long userId, Integer type, BigDecimal amount) {
        List<UserCoupon> queryAllByType = userCouponService.queryAllByType(userId, type, amount);
        return RestResponse.success(queryAllByType, "Queried successfully");
    }
}