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

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;

import net.northking.cctp.scriptcase.api.component.service.ReBusComponentInfoApiService;
import net.northking.cctp.scriptcase.dto.component.*;
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;

/**
 * 业务组件表_发布 => Restful 类型 HTTP/HTTPS 接口
 *
 * @author maven-cctp-plugin
 * @since 1.0
 */
@Api(tags = "业务组件表_发布")
@RequestMapping("/v1/ReBusComInfos")
@RestController
public class ReBusComponentInfoRestfulCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(ReBusComponentInfoRestfulCtrl.class);

  @Autowired
  private ReBusComponentInfoApiService apiService;


  /**
   * 业务组件生成
   */
  @ApiOperation(value = "录制:脚本生产业务组件")
  @RequiredPermissions("ui-updateScript")
  @PostMapping(
          value = "/record/genBusComponent",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<ReBusComponentInfoDetailDto> genBusComponent(
          @RequestBody @Validated ReBusComponentInfoAddDto inputDto)
  {
    ResultWrapper<ReBusComponentInfoDetailDto> wrapper = new ResultWrapper<>();
    ReBusComponentInfoDetailDto dto = apiService.genBusComponent(inputDto);
    return wrapper.success(dto);
  }

  @ApiOperation(value = "录制接口:查看业务组件树")
  @PostMapping(value = "/record/getComTreeByType",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<RecordComTreeDto>> getComTreeByType(
          @RequestBody @Validated RecordComTreeQueryDto query)
  {
    ResultWrapper<List<RecordComTreeDto>> wrapper = new ResultWrapper<>();
    List<RecordComTreeDto> list = apiService.getComTreeByType(query);

    return wrapper.success(list);
  }

  @ApiOperation(value = "录制接口:查看组件树模糊搜索")
  @PostMapping(value = "/record/getComTreeForLike",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<RecordComTreeLikeDto> getComTreeForLike(
          @RequestBody @Validated RecordComTreeQueryDto query)
  {
    ResultWrapper<RecordComTreeLikeDto> wrapper = new ResultWrapper<>();
    RecordComTreeLikeDto list = apiService.getComTreeForLike(query);

    return wrapper.success(list);
  }


  @ApiOperation(value = "录制接口:根据组件id查询组件信息")
  @PostMapping(value = "/record/getComListByIds",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<ReBusComponentInfoQueryDto> getComListByIds(
          @RequestBody @Validated ReBusComponentInfoQueryDto query)
  {
    ResultWrapper<ReBusComponentInfoQueryDto> wrapper = new ResultWrapper<>();
    ReBusComponentInfoQueryDto result = apiService.getComListByIds(query);

    return wrapper.success(result);
  }
}
