package com.qmth.paper.library.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.paper.library.business.enums.EnumType;
import com.qmth.paper.library.common.contant.ApiPrefixConstant;
import com.qmth.paper.library.common.enums.*;
import com.qmth.paper.library.common.util.Result;
import com.qmth.paper.library.common.util.ResultUtil;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 枚举类型查询接口
 */
@Api(tags = "枚举类型Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + ApiPrefixConstant.PREFIX_COMMON + "/get_enums")
public class EnumsController {

    /**
     * 查询
     *
     * @param type 类型
     */
    @RequestMapping(method = RequestMethod.POST)
    public Result list(@RequestParam(value = "type", required = true) String type) {
        if (StringUtils.isBlank(type)) {
            throw ExceptionResultEnum.ERROR.exception("类型不能为空");
        }

        List<EnumResult> list = null;
        if (type.equals(EnumType.PRIVILEGE_TYPE.name())) {
            //菜单类型
            list = PrivilegeEnum.listTypes();
        } else if (type.equals(EnumType.ROLE_TYPE.name())) {
            //内置角色类型
            list = RoleTypeEnum.listTypes(false);
        } else if (type.equals(EnumType.SYSTEM_CODE_ENUM.name())) {
            // 系统自生成编码
            list = SystemCodeEnum.listTypes();
        } else if (type.equals(EnumType.TB_TASK_STATUS.name())) {
            // 同步云阅卷日志表状态类型
            list = TaskStatusEnum.listTypes();
        }
        return ResultUtil.ok(list);
    }
}
