/*
* Copyright (c) 京北方信息技术股份有限公司 Corporation 2023 . All rights reserved.
*
*/
package net.northking.cctp.scriptcase.api.caseDataSet;

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import com.hzbank.testteam.autotest.dependencies.authDependency.constants.AuthDependencyConstants;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.constants.BaseDefineDependencyConstants;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.northking.cctp.common.db.Pagination;
import net.northking.cctp.common.dto.AdvancedQueryOptions;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.scriptcase.api.caseDataSet.service.AtuCaseDataSetApiService;
import net.northking.cctp.scriptcase.dto.atuScript.atuScriptInfo.PrincipalUpdateDto;
import net.northking.cctp.scriptcase.dto.caseDataSet.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用例集目录表")
@RequestMapping("/v1")
@RestController
public class AtuCaseDataSetQueryCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(AtuCaseDataSetQueryCtrl.class);

  @Autowired
  private AtuCaseDataSetApiService apiService;

  /**
   * 分页查询
   *
   * @param queryByPage  查询条件
   * @return 数据列表
   */
  @ApiOperation(value = "分页查询列表：用例集目录表")
  @PostMapping(value = "/paging/query/AtuCaseDataSets",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Pagination<AtuCaseDataSetDetailDto>> pagingQuery(
      @RequestBody @Validated QueryByPage<AtuCaseDataSetQueryDto> queryByPage)
  {
    ResultWrapper<Pagination<AtuCaseDataSetDetailDto>> wrapper = new ResultWrapper<>();
    Pagination<AtuCaseDataSetDetailDto> page = apiService.pagingQuery(queryByPage);

    return wrapper.success(page);
  }

  @ApiOperation(value = "查询用例集目录")
  @PostMapping(value = "/query/setTree",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<AtuCaseDataSetMenuDto>> querySetTree(@RequestBody AtuSetTreeQueryDto dto) {
    ResultWrapper<List<AtuCaseDataSetMenuDto>> wrapper = new ResultWrapper<>();
    List<AtuCaseDataSetMenuDto> result = apiService.querySetTree(dto);
    return wrapper.success(result);
  }

  @ApiOperation(value = "用例集目录下的脚本")
  @RequiredPermissions("caseSetManagement")
  @PostMapping(value = "/query/script/byPath",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Pagination<AtuCaseScriptResultDto>> queryScriptByPath(@RequestBody QueryByPage<AtuCaseScriptQueryDto> dto){
    ResultWrapper<Pagination<AtuCaseScriptResultDto>> wrapper = new ResultWrapper<>();
    Pagination<AtuCaseScriptResultDto> result = apiService.queryScriptByPath(dto);
    return wrapper.success(result);
  }

  @ApiOperation(value = "计划内查询用例集目录")
  @PostMapping(value = "/query/plan/setTree",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<AtuCaseDataSetMenuDto>> querySetTreeByPlan(@RequestBody AtuCaseDataSetFeignDto dto){
    ResultWrapper<List<AtuCaseDataSetMenuDto>> wrapper = new ResultWrapper<>();
    List<AtuCaseDataSetMenuDto> result = apiService.queryPlanSetTree(dto);
    return wrapper.success(result);
  }

  @ApiOperation(value = "计划内查询用例集下的脚本")
  @PostMapping(value = "/query/plan/scriptBySet",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Pagination<AtuCaseScriptResultDto>> queryScriptByPlan(@RequestBody QueryByPage<AtuCaseScriptQueryDto> dto){
    ResultWrapper<Pagination<AtuCaseScriptResultDto>> wrapper = new ResultWrapper<>();
    Pagination<AtuCaseScriptResultDto> result = apiService.queryScriptByPlan(dto);
    return wrapper.success(result);
  }

  @RequiredPermissions("ui-updateSetPrincipal")
  @ApiOperation(value = "更新负责人")
  @PostMapping(value = "/update/set/principal",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> updatePrincipal(@RequestBody PrincipalUpdateDto dto){
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer result = this.apiService.updatePrincipal(dto);
    return wrapper.success(result);
  }

  @ApiOperation(value = "feign调用:查询计划勾选的脚本")
  @PostMapping(value = "/feign/query/scriptId",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public List<AtuPlanScriptReturnDto> feignQueryScriptId(@RequestBody AtuPlanScriptSaveDto dto){
    return this.apiService.feignQueryScriptId(dto);
  }



    @ApiOperation(value = "获取高级查询相关配置数据:创建人，更新人，责任人")
    @GetMapping(value = "/AtuCaseDataSets/advancedQueryOptions")
    public ResponseVO<AdvancedQueryOptions> advancedQueryOptions(
            @ApiParam(value = "系统ID", required = true, example = "36602691803153920")
            @RequestHeader(AuthDependencyConstants.REQUEST_HEADER_PROJECT_ID) String projectId) {
      logger.debug("start advancedQueryOptions");
      ResponseVO<AdvancedQueryOptions> responseVO = new ResponseVO<>();
      AdvancedQueryOptions result = apiService.advancedQueryOptions(projectId);
      responseVO.setCode(BaseDefineDependencyConstants.SYSTEM_RESPONSE_CODE_SUCCESS);
      responseVO.setData(result);
      responseVO.setMessage("获取成功");
      logger.debug("end advancedQueryOptions");
      return responseVO;
    }
}


