package com.ruoyi.web.controller.mch;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.ss.vip.domain.Vip;
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @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("商户新增VIP")
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.FrontCreate.class) Vip data) {
        // TODO
        return success();
    }

}
