package net.northking.cctp.device.api.pcDevice;

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.db.Pagination;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.device.api.pcDevice.service.CdPcDeviceApiService;
import net.northking.cctp.device.dto.pcDevice.CdPcDeviceDetailDto;
import net.northking.cctp.device.dto.pcDevice.CdPcDeviceQueryDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.integration.redis.util.RedisLockRegistry;
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;

@Api(tags = "PC设备信息(SaaS)")
@RequestMapping("/v1")
@RestController
public class CdPcDeviceSaaSCtrl {
    /**
     * 日志
     */
    private final static Logger logger = LoggerFactory.getLogger(CdPcDevicePlatformCtrl.class);

    @Autowired
    private CdPcDeviceApiService cdPcDeviceApiService;

    @Autowired
    private RedisLockRegistry redisLockRegistry;

    @ApiOperation(value = "分页查询列表(租户)")
    @RequiredPermissions("sassPCDeviceManage")
    @PostMapping(value = "/paging/query/pc-devices/tenant",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<Pagination<CdPcDeviceDetailDto>> pagingQueryByTenant(
            @RequestBody QueryByPage<CdPcDeviceQueryDto> queryByPage){
        ResultWrapper<Pagination<CdPcDeviceDetailDto>> wrapper = new ResultWrapper<>();
        Pagination<CdPcDeviceDetailDto> page = cdPcDeviceApiService.pagingQueryByTenant(queryByPage);
        return wrapper.success(page);
    }

    @ApiOperation(value = "查询未分配租户的pc设备")
    @PostMapping(value = "/paging/query/pc-devices/none/tenant",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<Pagination<CdPcDeviceDetailDto>> pagingNoneTenant(
            @RequestBody QueryByPage<CdPcDeviceQueryDto> queryByPage){
        ResultWrapper<Pagination<CdPcDeviceDetailDto>> wrapper = new ResultWrapper<>();
        Pagination<CdPcDeviceDetailDto> page = cdPcDeviceApiService.pagingNoneTenant(queryByPage);
        return wrapper.success(page);
    }

    @ApiOperation(value = "查询已分配租户的pc设备")
    @PostMapping(value = "/paging/query/pc-devices/deviceByTenant",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<Pagination<CdPcDeviceDetailDto>> deviceByTenant(
            @RequestBody QueryByPage<CdPcDeviceQueryDto> queryByPage){
        ResultWrapper<Pagination<CdPcDeviceDetailDto>> wrapper = new ResultWrapper<>();
        Pagination<CdPcDeviceDetailDto> page = cdPcDeviceApiService.pagingByTenant(queryByPage);
        return wrapper.success(page);
    }

}
