package com.ruoyi.web.controller.app;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.vip.domain.VipQuery;
import com.ruoyi.ss.vip.domain.VipVO;
import com.ruoyi.ss.vip.service.VipService;

import io.swagger.annotations.ApiOperation;


@RestController
@RequestMapping("/app/vip")
public class AppVipController extends BaseController {

    @Autowired
    private VipService vipService;

    @ApiOperation("查询本人会员列表")
    @GetMapping("/list")
    public TableDataInfo list(VipQuery query) {
        startPage();
        query.setUserId(getUserId());
        List<VipVO> list = vipService.selectVipList(query);
        return getDataTable(list);
    }

    @ApiOperation("查询本人在店铺可用的折扣最低的会员")
    @GetMapping("/availableMinDiscount")
    public AjaxResult availableMinDiscount(Long storeId) {
        PageHelper.startPage(1, 1);
        PageHelper.orderBy("discount asc");
        List<VipVO> list = vipService.selectUserAvaliableStoreVip(getUserId(), storeId);
        return AjaxResult.success(CollectionUtils.getFirst(list));
    }

    @ApiOperation("查询可用会员列表")
    @GetMapping("/availableList")
    public TableDataInfo availableList(VipQuery query) {
        startPage();
        query.setUserId(getUserId());
        List<VipVO> list = vipService.selectAvailableList(query);
        return getDataTable(list);
    }

}
