package io.wdd.agent.executor.web;


import io.wdd.agent.executor.CommandExecutor;
import io.wdd.agent.executor.FunctionExecutor;
import io.wdd.common.beans.executor.ExecutionMessage;
import io.wdd.common.beans.response.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;

@RestController
@RequestMapping("testExecutor")
public class TestCommandExecutorController {

    @Resource
    CommandExecutor commandExecutor;

    @Resource
    FunctionExecutor functionExecutor;


    @PostMapping("comand")
    public R<String> testFor(
            @RequestBody ExecutionMessage executionMessage
    ) {

        return R.ok("1");
    }


    @PostMapping("linuxFile")
    public R<String> testLinuxFile(
            @RequestParam(value = "streamKey") String streamKey,
            @RequestParam(value = "command") String messageType
    ){

        ExecutionMessage executionMessage = ExecutionMessage.builder()
                .resultKey(streamKey)
                .type(messageType)
                .singleLineCommand(Collections.singletonList(messageType))
                .build();

        System.out.println("executionMessage = " + executionMessage);

        functionExecutor.execute(null, executionMessage, false);

        return R.ok(streamKey);
    }

}
