package cd.casic.module.terminal.controller;

import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.module.terminal.service.impl.TerminalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static cd.casic.framework.commons.pojo.CommonResult.success;

/**
 *
 * 终端连接
 * @author Yuru Pu
 * @version 1.0
 * @since 2025/7/8 11:36
 */
@Tag(name = "管理后台 - 终端")
@RestController
@RequestMapping("/asset/terminal")
@Validated
public class TerminalController {

    @Resource
    private TerminalService terminalService;

    @GetMapping("/access")
    @Operation(summary = "获取终端key")
    @PreAuthorize("@ss.hasPermission('terminal:access')")
    public CommonResult getTerminalAccessToken() {
        return success(terminalService.getTerminalAccessToken());
    }

    @GetMapping("/transfer")
    @Operation(summary = "获取终端 transferToken")
    @PreAuthorize("@ss.hasPermission('asset:terminal:access')")
    public CommonResult<String> getTerminalTransferToken() {
        return success(terminalService.getTerminalTransferToken());
    }

    @GetMapping("/test")
    @Operation(summary = "测试主机连接")
//    @PreAuthorize("@ss.hasPermission('asset:host:update')")
    public CommonResult testHostConnect(@RequestParam Long id) {
        return terminalService.testHostConnect(id);
    }

}

