package net.northking.cctp.scriptcase.pub;

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 lombok.extern.slf4j.Slf4j;
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.IdAndStatusDto;
import net.northking.cctp.scriptcase.dto.caseDataSet.AtuCaseDataSetMenuDto;
import net.northking.cctp.scriptcase.dto.caseDataSet.AtuCaseScriptQueryDto;
import net.northking.cctp.scriptcase.dto.caseDataSet.AtuCaseScriptResultDto;
import net.northking.cctp.scriptcase.dto.caseDataSet.PicusQueryDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用例集目录表（服务间调用）")
@RequestMapping("/pub")
@RestController
@Slf4j
public class AtuCaseDataSetPub {

    @Autowired
    private AtuCaseDataSetApiService apiService;

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

    @ApiOperation(value = "啄木鸟查询用例集脚本Id集合")
    @PostMapping(value = "/picus/query/scriptIds",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<List<IdAndStatusDto>> picusQueryByScriptIds(@RequestBody List<String> ids) {
        ResultWrapper<List<IdAndStatusDto>> wrapper = new ResultWrapper<>();
        List<IdAndStatusDto> result = apiService.picusQueryByScriptIds(ids);
        return wrapper.success(result);
    }

    @ApiOperation(value = "用例集目录下的脚本")
    @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 = "获取高级查询相关配置数据:创建人，更新人，责任人")
    @GetMapping(value = "/AtuCaseDataSets/advancedQueryOptions")
    public ResponseVO<AdvancedQueryOptions> picusAdvancedQueryOptions(
            @ApiParam(value = "系统ID", required = true, example = "36602691803153920")
            @RequestParam("projectId") String projectId) {
        log.debug("start advancedQueryOptions");
        ResponseVO<AdvancedQueryOptions> responseVO = new ResponseVO<>();
        AdvancedQueryOptions result = apiService.picusAdvancedQueryOptions(projectId);
        responseVO.setCode(BaseDefineDependencyConstants.SYSTEM_RESPONSE_CODE_SUCCESS);
        responseVO.setData(result);
        responseVO.setMessage("获取成功");
        log.debug("end advancedQueryOptions");
        return responseVO;
    }
}
