package com.ruoyi.cai.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cai.dto.app.query.BlackQuery;
import com.ruoyi.cai.dto.app.vo.user.UserListVo;
import com.ruoyi.cai.service.UserBlacklistService;
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.helper.LoginHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user/black")
@Tag(name = "用户黑名单接口")
public class UserBlackAppController {

    @Autowired
    private UserBlacklistService userBlacklistService;

    @GetMapping("page")
    @Operation(summary = "用户黑名单查询")
    public TableDataInfo<UserListVo> page(PageQuery pageQuery){
        Page<UserListVo> page = userBlacklistService.pageApp(pageQuery, LoginHelper.getUserId());
        return TableDataInfo.build(page);
    }

    @PostMapping("black")
    @Operation(summary = "拉黑操作 如果已经给拉黑则放开")
    public R<Boolean> black(@RequestBody BlackQuery query){
        Long userId = LoginHelper.getUserId();
        boolean b = userBlacklistService.black(userId,query.getBlackUserId(),query.getActionType());
        return R.ok(b);
    }
}
