package cn.axzo.workflow.client.feign.manage;

import cn.axzo.workflow.client.annotation.WorkflowEngineFeignClient;
import cn.axzo.workflow.common.annotation.InvokeMode;
import cn.axzo.workflow.common.annotation.Manageable;
import cn.axzo.workflow.common.model.request.category.*;
import cn.axzo.workflow.common.model.response.BpmPageResult;
import cn.axzo.workflow.common.model.response.category.CategoryConfigItemVO;
import cn.axzo.workflow.common.model.response.category.CategoryGroupVarItemVo;
import cn.axzo.workflow.common.model.response.category.CategoryItemVO;
import cn.azxo.framework.common.model.CommonResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.*;


/**
 * OMS流程业务管理API
 *
 * @author zuoqinbo
 * @version V1.0
 * @date 2023/11/6 16:01
 */

//@FeignClient(name = "workflow-engine", url = "${axzo.service.workflow-engine:http://workflow-engine:8080}", configuration = CommonFeignConfiguration.class)
@WorkflowEngineFeignClient
@Manageable
public interface ProcessCategoryApi {

    /**
     * 获取指定业务分类
     *
     * @return
     */
    @GetMapping("/api/process/category/get")
    @InvokeMode(SYNC)
    CommonResponse<CategoryItemVO> get(@RequestParam Long id);

    /**
     * 获取指定业务分类集合
     *
     * @param ids
     * @return
     */
    @GetMapping("/api/process/category/getByIds")
    @InvokeMode(SYNC)
    CommonResponse<List<CategoryItemVO>> getByIds(@RequestParam List<Long> ids);

    /**
     * 获取指定业务分类集合
     *
     * @param values
     * @return
     */
    @GetMapping("/api/process/category/getByValues")
    @InvokeMode(SYNC)
    CommonResponse<List<CategoryItemVO>> getByValues(@RequestParam List<String> values);

    /**
     * 新增业务分类
     *
     * @return
     */
    @PostMapping("/api/process/category/create")
    @InvokeMode(SYNC)
    CommonResponse<CategoryItemVO> create(@Validated @RequestBody CategoryCreateDTO req);

    /**
     * 更新业务分类
     *
     * @return
     */
    @PutMapping("/api/process/category/update")
    @InvokeMode(SYNC)
    CommonResponse<CategoryItemVO> update(@Validated @RequestBody CategoryUpdateDTO dto);

    /**
     * 删除指定业务分类
     *
     * @param id
     * @return
     */
    @DeleteMapping("/api/process/category/delete")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> delete(@RequestParam Long id);

    /**
     * 更新指定分类状态
     *
     * @param id
     * @param state
     * @return
     */
    @PutMapping("/api/process/category/update/state")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> updateState(@RequestParam Long id, @RequestParam Boolean state);

    /**
     * 获取指定业务分类集合
     *
     * @return
     */
    @PostMapping("/api/process/category/list")
    @InvokeMode(SYNC)
    CommonResponse<List<CategoryItemVO>> list(@RequestBody CategorySearchDTO dto);

    /**
     * 搜索业务分类
     *
     * @return
     */
    @PostMapping("/api/process/category/page/search")
    @InvokeMode(SYNC)
    CommonResponse<BpmPageResult<CategoryItemVO>> search(@RequestBody CategorySearchDTO dto);

    /**
     * 业务分类创建黑白名单配置项
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/process/category/config/create")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> createConfig(@RequestBody CategoryConfigCreateDTO dto);

    /**
     * 删除指定分类的配置项数据
     *
     * @param id
     * @return
     */
    @DeleteMapping("/api/process/category/config/delete/{id}")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> deleteConfig(@PathVariable Long id);

    /**
     * 业务分类黑白名单查询
     *
     * @return
     */
    @PostMapping("/api/process/category/config/page/search")
    @InvokeMode(SYNC)
    CommonResponse<BpmPageResult<CategoryConfigItemVO>> configSearch(@RequestBody CategoryConfigSearchDTO dto);

    /**
     * 更新业务分类的配置类型
     *
     * @param id
     * @param configType
     * @return
     */
    @PostMapping("/api/process/category/config/type/update")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> updateCategoryConfigType(@RequestParam Long id, @RequestParam String configType);

    /**
     * 用于业务方判断指定的业务分类的黑白名单配置
     *
     * @param tenantId     租户ID
     * @param categoryCode 业务分类编码
     * @return true: 可以发起创建流程实例, false: 不可用
     */
    @GetMapping("/api/process/category/check/status")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> checkCategoryStatus(@RequestParam Long tenantId, @RequestParam String categoryCode);

    /**
     * 查询分类对应的分组以及分组下的变量
     * @param dto 请求参数
     * @return 分组以及分组下的变量
     */
    @PostMapping("/api/process/category/group-with-vars/list")
    @InvokeMode(SYNC)
    CommonResponse<List<CategoryGroupVarItemVo>> searchCategoryGroupAndVars(@Validated @RequestBody CategoryGroupVarSearchDto dto);

    /**
     * 新增或者更新分组或者变量
     * @param dto 请求参数
     * @return 是否成功
     */
    @PostMapping("/api/process/category/group-with-vars/upsert")
    CommonResponse<Boolean> upsertCategoryGroupAndVars(@Validated @RequestBody CategoryGroupVarUpsertDto dto);
}
