package com.ruoyi.xq.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xq.domain.UserExtend;
import com.ruoyi.xq.dto.admin.user.UserExtendAdminVo;
import com.ruoyi.xq.dto.admin.user.req.UpdateIncomeCoinReq;
import com.ruoyi.xq.dto.admin.user.req.UpdateWxTransNumReq;
import com.ruoyi.xq.service.UserExtendService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 用户邀请
 *
 * @author 77
 * @date 2024-03-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xq/userExtend")
public class UserExtendController extends BaseController {

    private final UserExtendService userExtendService;

    /**
     * 查询用户邀请列表
     */
    @SaCheckPermission("xq:userExtend:list")
    @GetMapping("/list")
    public TableDataInfo<UserExtendAdminVo> list(UserExtendAdminVo bo, PageQuery pageQuery) {
        Page<UserExtendAdminVo> page = userExtendService.pageAdmin(pageQuery, bo);
        return TableDataInfo.build(page);
    }


    /**
     * 获取用户邀请详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xq:userExtend:query")
    @GetMapping("/{id}")
    public R<UserExtend> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(userExtendService.getById(id));
    }

    @SaCheckPermission("xq:userExtend:edit")
    @Log(title = "调整用户收益", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/updateIncomeCoin")
    public R<Void> updateIncomeCoin(@RequestBody UpdateIncomeCoinReq bo) {
        userExtendService.updateIncomeCoin(bo);
        return R.ok();
    }

    @SaCheckPermission("xq:userExtend:edit")
    @Log(title = "调整用户微信次数", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/updateWxTransNum")
    public R<Void> updateWxTransNum(@RequestBody UpdateWxTransNumReq bo) {
        userExtendService.updateWxTransNum(bo);
        return R.ok();
    }

}
