package cn.hanghui.outapi.platform.tenant.controller;

import cn.hanghui.outapi.platform.common.entity.rest.RestResult;
import cn.hanghui.outapi.platform.common.exception.BusinessException;
import cn.hanghui.outapi.platform.common.utils.AppTokenUtil;
import cn.hanghui.outapi.platform.tenant.entity.dto.blacklist.UserBlacklistBean;
import cn.hanghui.outapi.platform.tenant.entity.dto.blacklist.UserBlacklistOpenSearch;
import cn.hanghui.outapi.platform.tenant.entity.dto.blacklist.UserBlacklistSearch;
import cn.hanghui.outapi.platform.tenant.service.UserBlacklistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author shisl
 * @package cn.hanghui.outapi.platform.tenant.controller
 * @class DeviceOpenApiController
 * @date 2024/8/30 上午10:12
 * @description 设备开放api入口
 */
@Api(tags = "设备开放api入口")
@Validated
@RestController
@RequestMapping("/api/v1/open/device")
public class DeviceOpenApiController {

    @Autowired
    private UserBlacklistService userBlacklistService;

    @ApiOperation(value = "本地黑名单获取")
    @PostMapping("/blacklist/query")
    public RestResult<List<UserBlacklistBean>> blacklist(@RequestBody @Valid UserBlacklistOpenSearch dto) {
        List<String> tokens = AppTokenUtil.getTokens();
        if (!tokens.contains(dto.getToken())) {
            throw new BusinessException("无权访问");
        }
        return userBlacklistService.queryBlacklist(dto);
    }


}
