package cd.casic.ci.api;

import cd.casic.ci.process.dto.req.trigger.TriggerQueryReq;
import cd.casic.framework.commons.pojo.CommonResult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
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.List;
/**
 * @pi.protocol: http
 * @pi.groupName: 流水线触发器控制器
 */
@RestController
@RequestMapping("/trigger")
public class TriggerController {
    /**
     * @pi.name:条件查询流水线触发器信息
     * @pi.path:/trigger/findAllTrigger
     * @pi.methodType:post
     * @pi.request-type:json
     * @pi.param: model=triggerQuery
     */
    @PostMapping(path="/findAllTrigger")
    public CommonResult<List<Object>> findAllTrigger(@RequestBody @Valid @NotNull TriggerQueryReq triggerQuery) {
//        List<Object> list = triggerServer.findAllTrigger(triggerQuery);
        String triggers = "[\n" +
                "  {\n" +
                "    \"timeId\": \"3e0ef2372dfc\",\n" +
                "    \"taskType\": 1,\n" +
                "    \"date\": 1,\n" +
                "    \"time\": \"16:00\",\n" +
                "    \"triggerId\": \"9f2ca05e88d4\",\n" +
                "    \"cron\": \"00 00 16 12 5 ? 2025\",\n" +
                "    \"weekTime\": \"2025-5-12 16:00:00\",\n" +
                "    \"execTime\": \"周一 | 周二 | 周三 | 16:00\",\n" +
                "    \"timeList\": [\n" +
                "      1,\n" +
                "      2,\n" +
                "      3\n" +
                "    ],\n" +
                "    \"dayTime\": null,\n" +
                "    \"type\": 81,\n" +
                "    \"name\": null,\n" +
                "    \"state\": \"1\"\n" +
                "  }\n" +
                "]";
        JSONArray objects = JSON.parseArray(triggers);
        return CommonResult.success(objects);
    }
}
