package net.northking.cctp.se.plan;

import io.swagger.annotations.Api;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.se.plan.bean.EnginePlanQuery;
import net.northking.cctp.se.plan.servcie.EnginePlanInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 自动化测试计划：委托、移除
 */
@RequestMapping(value = "/v1")
@RestController
@Api(tags = "自动化测试计划：委托、移除")
public class AutomationTestPlanCtrl
{

  private final EnginePlanInfoService apiService;

  public AutomationTestPlanCtrl(EnginePlanInfoService apiService){
    this.apiService = apiService;
  }


  @Autowired
  private AtuPlanTaskSchedule schedule;
  /**
   * TODO 委托执行计划
   *
   * @param requestBody
   * @param request
   * @param response
   * @return
   */
  @PostMapping(value = "/plan/entrust",
      produces = MediaType.APPLICATION_JSON_VALUE,
      consumes = MediaType.APPLICATION_JSON_VALUE)
  public ResultWrapper<Object> entrust(@RequestBody EnginePlanQuery requestBody,
      HttpServletRequest request,
      HttpServletResponse response
  )
  {
    ResultWrapper<Object> wrapper = new ResultWrapper<>();
    Integer integer = apiService.entrustEnginPlan(requestBody);
    return wrapper.success(integer);
  }

  /**
   * TODO 移除执行计划
   *
   * @param batchId
   * @param request
   * @param response
   * @return
   */
  @PostMapping(value = "/plan/remove",
      produces = MediaType.APPLICATION_JSON_VALUE,
      consumes = MediaType.APPLICATION_JSON_VALUE)
  public ResultWrapper<Object> remove(@RequestBody
      String batchId,
      HttpServletRequest request,
      HttpServletResponse response
  )
  {
    ResultWrapper<Object> wrapper = new ResultWrapper<>();
    Integer integer = apiService.removeEnginePlan(batchId);
    return wrapper.success(integer);
  }


}
