package com.backendsys.modules.sdk.baidu.yunapp.controller;

import com.backendsys.modules.common.config.security.annotations.Anonymous;
import com.backendsys.modules.common.utils.Result;
import com.backendsys.modules.sdk.baidu.yunapp.entity.AppOperateParams;
import com.backendsys.modules.sdk.baidu.yunapp.entity.ExecuteScriptParams;
import com.backendsys.modules.sdk.baidu.yunapp.entity.TaskParams;
import com.backendsys.modules.sdk.baidu.yunapp.entity.ScreenshotParams;
import com.backendsys.modules.sdk.baidu.yunapp.service.YunappService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Tag(name = "云手机")
public class YunappController {

    @Autowired
    private YunappService yunappService;

    @Anonymous
    @Operation(summary = "实例执行脚本")
    @PostMapping("/api/yunapp/executeScript")
    public Result executeScript(@RequestBody ExecuteScriptParams executeScriptParams) {
        return Result.success().put("data", yunappService.executeScript(executeScriptParams));
    }

    @Anonymous
    @Operation(summary = "任务结果查询 (通用)")
    @PostMapping("/api/yunapp/executeScriptInfo")
    public Result executeScriptInfo(@RequestBody TaskParams taskParams) {
        return Result.success().put("data", yunappService.executeScriptInfo(taskParams.getTask_ids()));
    }

    @Anonymous
    @Operation(summary = "实例截图")
    @PostMapping("/api/yunapp/screenshot")
    public Result screenshot(@RequestBody ScreenshotParams screenshotParams) {
        return Result.success().put("data", yunappService.screenshot(screenshotParams));
    }

    @Anonymous
    @Operation(summary = "实例截图查询")
    @PostMapping("/api/yunapp/screenshotInfo")
    public Result screenshotInfo(@RequestBody TaskParams taskParams) {
        return Result.success().put("data", yunappService.screenshotInfo(taskParams.getTask_ids()));
    }

    @Anonymous
    @Operation(summary = "应用启停")
    @PostMapping("/api/yunapp/appOperate")
    public Result appOperate(@RequestBody AppOperateParams appOperateParams) {
        return Result.success().put("data", yunappService.appOperate(appOperateParams));
    }

}
