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

import cn.hutool.json.JSONUtil;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.constants.BaseDefineDependencyConstants;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.vo.ApiScriptOptionVO;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.scriptcase.api.atuScript.service.AtuScriptInfoApiService;
import net.northking.cctp.scriptcase.dto.atuScript.atuScriptInfo.AtuPlanScriptDetailDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>Title: ScriptPubCtrl</p>
 * <p>Description: </p>
 *
 * @Author chenjianfeng
 * @Version V1.0
 * @Date 2023/09/04
 * <p>Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved.</p>
 */
@Api(tags = "脚本管理公共接口")
@RequestMapping("/pub/script")
@RestController
@Slf4j
public class ScriptPubCtrl {

    private final static Logger logger = LoggerFactory.getLogger(ScriptPubCtrl.class);

    @Autowired
    private AtuScriptInfoApiService scriptInfoApiService;

    /**
     * 查询脚本详细信息
     * @param scriptIdSet 脚本id集合
     * @return 结果集
     */
    @ApiOperation(value = "查询脚本详细信息")
    @PostMapping(value = "/queryScriptDetailMap")
    ResultWrapper<Map<String, AtuPlanScriptDetailDto>> queryScriptDetailMap(@RequestBody Set<String> scriptIdSet){

        logger.info("start queryScriptDetailMap ... ");
        logger.info("queryScriptDetailMap params => " + JSONUtil.toJsonStr(scriptIdSet));

        ResultWrapper<Map<String, AtuPlanScriptDetailDto>> wrapper = new ResultWrapper<>();
        Map<String, AtuPlanScriptDetailDto> scriptDetailMap = scriptInfoApiService.queryScriptDetailMap(scriptIdSet);

        logger.info("end queryScriptDetailMap ... ");

        return wrapper.success(scriptDetailMap);
    }


    @ApiOperation(value = "根据脚本ids获取脚本数据")
    @PostMapping(value = "/getUIScriptVOByIds")
    public ResponseVO<List<ApiScriptOptionVO>> getUIScriptVOByIds(@RequestBody List<String> scriptIdList) {
        ResponseVO<List<ApiScriptOptionVO>> responseVO = new ResponseVO<>();
        List<ApiScriptOptionVO> ApiScriptOptionVOs = scriptInfoApiService.getUIScriptVOByIds(scriptIdList);
        responseVO.setCode(BaseDefineDependencyConstants.SYSTEM_RESPONSE_CODE_SUCCESS);
        responseVO.setData(ApiScriptOptionVOs);
        return responseVO;
    }

    @ApiOperation(value = "根据脚本编号，系统id获取脚本信息列表")
    @PostMapping(value = "/getUIScriptVOByCodeAndSystemId")
    public ResponseVO<List<ApiScriptOptionVO>> getUIScriptVOByCodeAndSystemId(@RequestParam(value = "scriptCode",required =false) String scriptCode,
                                                                              @RequestParam(value ="systemId",required =false) String systemId) {
        ResponseVO<List<ApiScriptOptionVO>> responseVO = new ResponseVO<>();
        List<ApiScriptOptionVO> ApiScriptOptionVOs = scriptInfoApiService.getUIScriptVOByCodeAndSystemId(scriptCode, systemId);
        responseVO.setData(ApiScriptOptionVOs);
        responseVO.setCode(BaseDefineDependencyConstants.SYSTEM_RESPONSE_CODE_SUCCESS);
        return responseVO;
    }
}
