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

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.caseDataSet.service.AtuCaseDataSetApiService;
import net.northking.cctp.scriptcase.dto.caseDataSet.AtuCaseDataSetAddDto;
import net.northking.cctp.scriptcase.dto.caseDataSet.AtuCaseDataSetUpdateDto;
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/batch/AtuCaseDataSets")
@RestController
public class AtuCaseDataSetBatchCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(AtuCaseDataSetBatchCtrl.class);

  @Autowired
  private AtuCaseDataSetApiService apiService;

  /**
   * Restful接口-post： 批量新增用例集目录表
   *
   * @param batch 集合
   * @return 主键集合
   */
  @ApiOperation(value = "批量新增：用例集目录表")
  @PostMapping(
      value = "/insert",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<String>> addBatch(
      @RequestBody @Validated List<AtuCaseDataSetAddDto> batch)
  {
    ResultWrapper<List<String>> wrapper = new ResultWrapper<>();
    List<String> result = this.apiService.addBatch(batch);
    return wrapper.success(result);
  }

  /**
   * Restful接口-post： 批量修改用例集目录表
   *
   * @param batch 集合
   * @return 成功的数量
   */
  @ApiOperation(value = "批量修改：用例集目录表")
  @PostMapping(
      value = "/update",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> updateBatch(
      @RequestBody @Validated List<AtuCaseDataSetUpdateDto> batch) throws IllegalAccessException
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = this.apiService.updateBatch(batch);
    return wrapper.success(count);
  }

  /**
   * Restful接口-post： 批量删除用例集目录表
   *
   * @param batch 集合
   * @return 成功的数量
   */
  @RequiredPermissions({"ui-deleteCaseDataSets","ui-deleteCaseDataSet"})
  @ApiOperation(value = "批量删除：用例集目录表")
  @PostMapping(
      value = "/delete",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> deleteBatch(
      @RequestBody @Validated List<Object> batch)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = this.apiService.deleteBatch(batch);
    return wrapper.success(count);
  }
}
