package org.wfc.user.controller;

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.GetMapping;
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 org.wfc.common.core.domain.LoginUser;
import org.wfc.common.core.domain.R;
import org.wfc.common.core.web.controller.BaseController;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.common.security.utils.SecurityUtils;
import org.wfc.user.api.domain.bo.UClientBo;
import org.wfc.user.domain.vo.UClientCurrentVo;
import org.wfc.user.domain.vo.UClientHistoryUserVo;
import org.wfc.user.service.IUClientService;

import java.util.List;

/**
 * <p>
 * 用户平台_AP设备表 前端控制器
 * </p>
 *
 * @author cyc
 * @since 2024-12-09
 */
@RestController
@RequestMapping("/client")
@Tag(name = "用户平台-终端设备接口")
public class UClientController extends BaseController {

    @Autowired
    private IUClientService clientService;

    /**
     * 根据设备mac保存或更新
     */
    @PostMapping("/recordClientUser")
    public R<Boolean> recordClientUser(@RequestBody UClientBo clientBo) {
        boolean result = clientService.recordClientUser(clientBo);
        return R.ok(result);
    }

    /**
     * 根据用户查询当前接入设备
     *
     * @return 结果
     */
    @Operation(summary = "当前设备")
    @GetMapping("/pageCurrentClient")
    public TableDataInfo getCurrentClients() {
        startPage();
        LoginUser<Object> loginUser = SecurityUtils.getLoginUser();

        List<UClientCurrentVo> result = clientService.getCurrentClients(loginUser.getUserid());
        return getDataTable(result);
    }

    /**
     * 根据用户查询历史设备
     *
     * @return 结果
     */
    @Operation(summary = "历史设备")
    @GetMapping("/pageHistoryClient")
    public TableDataInfo getHistoryByUser() {
        startPage();
        List<UClientHistoryUserVo> result = clientService.getHistoryByUser();
        return getDataTable(result);
    }

}
