package com.ruoyi.web.controller.mch;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
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.domain.ValidGroup;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.ss.vipLevel.domain.VipLevel;
import com.ruoyi.ss.vipLevel.domain.VipLevelQuery;
import com.ruoyi.ss.vipLevel.domain.VipLevelVO;
import com.ruoyi.ss.vipLevel.service.VipLevelConverter;
import com.ruoyi.ss.vipLevel.service.VipLevelService;

import io.swagger.annotations.ApiOperation;

/**
 * @author wjh
 * 2025/1/20
 */
@RestController
@RequestMapping("/mch/vipLevel")
public class MchVipLevelController extends BaseController {

    @Autowired
    private VipLevelService vipLevelService;

    @Autowired
    private VipLevelConverter vipLevelConverter;

    @ApiOperation("商户查询会员等级列表")
    @GetMapping("/list")
    public TableDataInfo list(VipLevelQuery query) {
        query.setMchId(getUserId());
        startPage();
        List<VipLevelVO> list = vipLevelService.selectVipLevelList(query);
        return getDataTable(list);
    }

    @ApiOperation("商户查询会员等级详情")
    @GetMapping("/{id}")
    public AjaxResult detail(@PathVariable Long id) {
        // TODO 校验权限
        return success(vipLevelService.selectVipLevelById(id));
    }

    @ApiOperation("商户新增会员等级")
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.FrontCreate.class) VipLevelVO data) {
        VipLevel po = vipLevelConverter.toPoByMchEdit(data);
        return toAjax(vipLevelService.insertVipLevel(po));
    }

    @ApiOperation("商户修改会员等级")
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.FrontUpdate.class) VipLevelVO data) {
        // TODO 校验权限

        VipLevel po = vipLevelConverter.toPoByMchEdit(data);
        return toAjax(vipLevelService.updateVipLevel(po));
    }

    @ApiOperation("商户删除会员等级")
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable List<Long> ids) {
        // TODO 校验权限
        return toAjax(vipLevelService.logicDel(ids));
    }

}
