package net.northking.cctp.flowable.pub;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.flowable.api.sm.service.StateProcessDefApiService;
import net.northking.cctp.flowable.dto.sm.StateAuthDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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;

import java.util.List;

@Api(tags = "状态授权")
@RequestMapping("/pub")
@RestController
public class StateAuthPubQueryCtrl {

    /**
     * 资源名称
     */
    private static final String RESOURCE_NAME = "/query/state";
    /**
     * 日志
     */
    private final static Logger logger = LoggerFactory.getLogger(StateAuthPubQueryCtrl.class);

    @Autowired
    private StateProcessDefApiService apiService;

    @ApiOperation(value = "获取状态")
    @PostMapping(value = RESOURCE_NAME + "/special",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<List<String>> queryInitialState(@RequestBody StateAuthDto stateAuth) {
        List<String> stateList  = apiService.querySpecialState(stateAuth);
        ResultWrapper<List<String>> wrapper = new ResultWrapper<>();
        return wrapper.success(stateList);
    }

    @ApiOperation(value = "获取状态下可选角色")
    @PostMapping(value = RESOURCE_NAME + "/role",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<List<String>> queryAvailableRoles(@RequestBody StateAuthDto stateAuth) {
        List<String> stateList = apiService.queryAvailableRoles(stateAuth);
        ResultWrapper<List<String>> wrapper = new ResultWrapper<>();
        return wrapper.success(stateList);
    }
}
