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

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.HisUseComponentApiService;
import net.northking.cctp.scriptcase.dto.component.HisUseComponentAddDto;
import net.northking.cctp.scriptcase.dto.component.RecordComTreeDto;
import net.northking.cctp.scriptcase.dto.component.RecordComTreeQueryDto;
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/HisUseComponents")
@RestController
public class HisUseComponentRestfulCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(HisUseComponentRestfulCtrl.class);

  @Autowired
  private HisUseComponentApiService apiService;

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

    return wrapper.success(list);
  }

  @ApiOperation(value = "录制接口:插入历史使用组件")
  @PostMapping(value = "/record/saveHisUseCom",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> saveHisUseCom(
          @RequestBody @Validated HisUseComponentAddDto dto)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer result = apiService.saveHisUseCom(dto);

    return wrapper.success(result);
  }
}
