package cn.axzo.workflow.server.controller.web.manage;

import cn.axzo.workflow.client.feign.manage.ProcessConfigApi;
import cn.axzo.workflow.common.enums.BpmnButtonEnum;
import cn.axzo.workflow.common.model.request.bpmn.BpmnButtonMetaInfo;
import cn.axzo.workflow.server.common.annotation.ErrorReporter;
import cn.azxo.framework.common.model.CommonResponse;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 流程引擎公共相关控制器
 *
 * @author zuoqinbo
 * @version V1.0
 * @date 2023/11/9 14:01
 */
@Slf4j
@RequestMapping({"/web/v1/api/process/config", "/api/process/config"})
@RestController
@ErrorReporter
@Validated
public class ProcessConfigController implements ProcessConfigApi {

    /**
     * 获取流程操作按钮列表
     *
     * @return 流程操作按钮列表
     */
    @Operation(summary = "获取流程操作按钮列表")
    @Override
    @GetMapping("button/list")
    public CommonResponse<List<BpmnButtonMetaInfo>> getDefaultButtons() {
        return CommonResponse.success(Arrays.stream(BpmnButtonEnum.values())
                .map(buttonEnum -> new BpmnButtonMetaInfo()
                        .setOrder(buttonEnum.getOrder())
                        .setBtnKey(buttonEnum.getBtnKey())
                        .setBtnName(buttonEnum.getBtnName())
                        .setChecked(false)
                        .setDisabled(false)).collect(Collectors.toList()));
    }
}
