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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.platform.api.comlibrary.service.CpComponentListApiService;
import net.northking.cctp.platform.dto.comlibrary.*;
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;
import java.util.Map;

/**
 * 组件清单 => Restful 类型 HTTP/HTTPS 接口
 *
 * @author maven-cctp-plugin
 * @since 1.0
 */
@Api(tags = "组件清单")
@RequestMapping("/v1/CpCompLists")
@RestController
public class CpComponentListRestfulCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(CpComponentListRestfulCtrl.class);

  @Autowired
  private CpComponentListApiService apiService;

  /**
   * Restful接口-get： 获取组件清单
   *
   * @param uuid       主键
   * @return 接口数据传输对象
   */
  @ApiOperation(value = "获取：组件清单详情信息")
  @GetMapping(
      value = "/{uuid}",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<CpComponentListDetailDto> findByPK(
      @PathVariable("uuid") String uuid)
  {
    ResultWrapper<CpComponentListDetailDto> wrapper = new ResultWrapper<>();
    CpComponentListDetailDto dto = apiService.findByPK(uuid);
    return wrapper.success(dto);
  }


  @ApiOperation(value = "组件列表:二级菜单")
  @PostMapping(value = "/query/getComponentTree",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<CpComLibraryTree>> getComponentTree(
          @RequestBody @Validated CpComponentLibraryQueryDto query)
  {
    ResultWrapper<List<CpComLibraryTree>> wrapper = new ResultWrapper<>();
    List<CpComLibraryTree> list = apiService.getComponentTree(query);

    return wrapper.success(list);
  }

  @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 = "/feign/getComTreeForLike",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<RecordComTreeDto>> getComTreeForLike(
          @RequestBody @Validated RecordComTreeQueryDto query)
  {
    ResultWrapper<List<RecordComTreeDto>> wrapper = new ResultWrapper<>();
    List<RecordComTreeDto> list = apiService.getComTreeForLike(query);

    return wrapper.success(list);
  }

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

    return wrapper.success(list);
  }

  @ApiOperation(value = "录制接口:查询组件信息——库名以及组件名")
  @PostMapping(value = "/record/getComInfoByName",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<CpComponentListDetailDto> getComInfoByName(
          @RequestBody @Validated RecordComInfoByNameDto query)
  {
    ResultWrapper<CpComponentListDetailDto> wrapper = new ResultWrapper<>();
    CpComponentListDetailDto result = apiService.getComInfoByName(query);

    return wrapper.success(result);
  }

  @ApiOperation(value = "feign:获取指定基础组件的信息")
  @PostMapping(value = "/record/getComInfoByIdList",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<RecordComTreeDto>> getComInfoByIdList(
          @RequestBody @Validated List<String> ids)
  {
    ResultWrapper<List<RecordComTreeDto>> wrapper = new ResultWrapper<>();
    List<RecordComTreeDto> list = apiService.getComInfoByIdList(ids);

    return wrapper.success(list);
  }

  @ApiOperation(value = "feign:获取指定基础组件的信息")
  @PostMapping(value = "/record/getComBasicInfoByIdList",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<Map<String,List<String>>>> getComBasicInfoByIdList(
          @RequestBody @Validated List<String> ids)
  {
    ResultWrapper<List<Map<String,List<String>>>> wrapper = new ResultWrapper<>();
    List<Map<String,List<String>>> list = apiService.getComBasicInfoByIdList(ids);

    return wrapper.success(list);
  }
}
