package org.matrix.autotest.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.matrix.autotest.utils.PageTools;
import org.matrix.database.entity.ExecutionRecord;
import org.matrix.database.service.IExecutionHistoryService;
import org.matrix.database.service.IExecutionRecordService;
import org.matrix.database.vo.CommonResult;
import org.matrix.database.vo.CommonResultObj;
import org.matrix.database.vo.ExecutionHistoryVo;
import org.matrix.enums.ExecutionRecType;
import org.matrix.socket.TestExecuteType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Optional;

/**
 * @author hxh
 */
@CrossOrigin
@RestController
@RequestMapping("/executionHistory")
@Api(tags = "对执行历史execution_history的基本操作")
public class ExecutionHistoryController {

    private final IExecutionHistoryService executionHistoryService;

    public ExecutionHistoryController(IExecutionHistoryService executionHistoryService) {
        this.executionHistoryService = executionHistoryService;
    }

    @GetMapping("/findExecutionHistory")
    public  ResponseEntity<CommonResultObj<IPage<ExecutionHistoryVo>>> findExecutionHistory(
                         @RequestParam(defaultValue = "10") int pageSize,
                         @RequestParam(defaultValue = "1") int pageNum,
                         @RequestParam(defaultValue = "-1") Long jobId,
                         Long caseId
                         ){
        IPage<ExecutionHistoryVo> page = executionHistoryService.pageByCaseIdAndJobId(caseId, jobId, pageNum, pageSize);
        return page.getRecords().size() != 0
                ? CommonResult.success(page, "查询成功")
                : CommonResult.failed(page, "查询失败或无数据");
    }
}
