package com.ruoyi.web.controller.mch;

import java.util.List;

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

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.ss.vip.domain.VipQuery;
import com.ruoyi.ss.vip.domain.VipVO;
import com.ruoyi.ss.vip.service.VipService;
import com.ruoyi.ss.vip.service.VipValidator;

import io.swagger.annotations.ApiOperation;

/**
 * @author wjh
 * 2024/12/10
 */
@RestController
@RequestMapping("/mch/vip")
public class MchVipController extends BaseController {

    @Autowired
    private VipService vipService;

    @Autowired
    private VipValidator vipValidator;

    @ApiOperation("商户获取VIP列表")
    @GetMapping("/list")
    public TableDataInfo list(VipQuery query) {
        startPage();
        query.setStoreMchId(getUserId());
        return getDataTable(vipService.selectVipList(query));
    }

    @ApiOperation("商户获取VIP详情")
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        VipVO vo = vipService.selectVipById(id);
        if (!vipValidator.canView(vo, getUserId())) {
            return error("您无权查看该信息");
        }
        return success(vo);
    }

    @ApiOperation("商户删除会员")
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable List<Long> ids) {
        // 校验权限
        List<VipVO> vipList = vipService.selectVipByIds(ids);
        if (vipValidator.canOperateAll(vipList, getUserId())) {
            return error("您无权删除该会员");
        }
        return toAjax(vipService.logicDel(ids));
    }

}
