package net.northking.cctp.scriptcase.api.ats;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.scriptcase.api.ats.service.AtsTestElementApiService;
import net.northking.cctp.scriptcase.dto.ats.AtsQueryDto;
import net.northking.cctp.scriptcase.dto.ats.ResultResponse;
import org.simpleframework.xml.core.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@Api(tags = "ats系统对接接口")
@RequestMapping("/v1/ats")
@RestController
public class AtsTestElementCtrl {
    /**
     * 日志
     */
    private final static Logger logger = LoggerFactory.getLogger(AtsTestElementCtrl.class);

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private AtsTestElementApiService apiService;

    /**
     * 分页显示自动化接口 列表
     *
     * @param query
     * @return 数据列表
     */
    @ApiOperation(value = "分页查询列表：自动化接口")
    @PostMapping(value = "/paging/scriptlist",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<ResultResponse> pagingQuery(@RequestBody @Validate AtsQueryDto query) {
        ResultWrapper<ResultResponse> wrapper = new ResultWrapper<>();
        ResultResponse page = apiService.getScriptList(query);
        return wrapper.success(page);
    }

    /**
     * 分页显示自动化接口 列表
     *
     * @param query
     * @return 数据列表
     */
    @ApiOperation(value = "分页查询列表：自动化场景")
    @PostMapping(value = "/paging/scenarios",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<ResultResponse> pagingScenarios(@RequestBody @Validate AtsQueryDto query) {
        ResultWrapper<ResultResponse> wrapper = new ResultWrapper<>();
        ResultResponse page = apiService.getScenarios(query);
        return wrapper.success(page);
    }

    @ApiOperation(value = "获取ATS地址以及ak")
    @GetMapping(value = "/getAtsConfig")
    public ResultWrapper<ResultResponse> getAtsConfig() {

        ResultWrapper<ResultResponse> wrapper = new ResultWrapper<>();
        ResultResponse resultResponse = apiService.getAtsConfig();

        return wrapper.success(resultResponse);

    }


}
