package cd.casic.ci.api;

import cd.casic.ci.process.dto.req.agent.AgentQueryReq;
import cd.casic.ci.process.dto.resp.agent.AgentResp;
import cd.casic.framework.commons.pojo.CommonResult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
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 java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/agent")
public class AgentController {
    @PermitAll
    @PostMapping(path="/findAgentList")
    public CommonResult<List<AgentResp>> findAgentList(@RequestBody @NotNull @Valid AgentQueryReq agentQuery){

//        List<Agent> agentList = agentService.findAgentList(agentQuery);
        String dataStr ="[\n" +
                "  {\n" +
                "    \"id\": \"c9ae1ff534db\",\n" +
                "    \"name\": \"local\",\n" +
                "    \"ip\": \"127.0.0.1\",\n" +
                "    \"tenantId\": \"default\",\n" +
                "    \"address\": \"local-default\",\n" +
                "    \"businessType\": \"default\",\n" +
                "    \"createTime\": \"2025-05-09 15:41:04\",\n" +
                "    \"displayType\": \"yes\",\n" +
                "    \"connect\": true\n" +
                "  }\n" +
                "]";
        JSONArray objects = JSON.parseArray(dataStr);
        List<AgentResp> data = new ArrayList<>(objects.size());
        for (Object object : objects) {
            AgentResp agentResp = JSON.parseObject(JSON.toJSONString(object), AgentResp.class);
            data.add(agentResp);
        }
        return CommonResult.success(data);
    }
}
