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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.db.Pagination;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.flowable.api.sm.service.StateProcessDeploymentApiService;
import net.northking.cctp.flowable.db.entity.SpDeployment;
import net.northking.cctp.flowable.dto.sm.StateProcessDeploymentDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 状态流程部署
 *
 * @author : xiusong.xie
 * @version : 1.0
 */
@Api(tags = "状态流程部署")
@RequestMapping("/v1")
@RestController
public class StateProcessDeploymentCtrl
{
  /**
   * 资源名称
   */
  private static final String RESOURCE_NAME = "/deployment/sp";
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(StateProcessDeploymentCtrl.class);

  private StateProcessDeploymentApiService apiService;

  /**
   * Restful接口-post： 部署状态流程
   *
   * @param inputDto 接口数据传输对象
   * @return 主键
   */
  @ApiOperation(value = "部署：状态流程")
  @PostMapping(
      value = RESOURCE_NAME,
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<String> add(
      @RequestBody @Validated StateProcessDeploymentDto inputDto)
  {
    ResultWrapper<String> wrapper = new ResultWrapper<>();
    String uuid = apiService.save(inputDto);  // TODO: 部署过程也就是和被关联的项目产生关联关系
    return wrapper.success(uuid);
  }


  /**
   * 分页查询
   *
   * @param queryByPage 查询条件
   * @return 数据列表
   */
  @ApiOperation(value = "分页查询列表：状态流程部署")
  @PostMapping(value = "/paging/query" + RESOURCE_NAME,
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Pagination<StateProcessDeploymentDto>> pagingQuery(
      @RequestBody @Validated QueryByPage<SpDeployment> queryByPage)
  {
    ResultWrapper<Pagination<StateProcessDeploymentDto>> wrapper = new ResultWrapper<>();
    Pagination<StateProcessDeploymentDto> page = apiService.pagingQuery(queryByPage);
    return wrapper.success(page);
  }
}
