package com.qmth.distributed.print.api;

import com.alibaba.fastjson.JSON;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.entity.BasicExamRule;
import com.qmth.distributed.print.business.enums.*;
import com.qmth.distributed.print.business.service.BasicExamRuleService;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.enums.*;
import com.qmth.teachcloud.common.enums.log.OperationTypeEnum;
import com.qmth.teachcloud.common.enums.mark.MarkArbitrateStatus;
import com.qmth.teachcloud.common.enums.mark.MarkProblemType;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.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 javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 枚举类型查询接口
 *
 * @Date: 2021/3/29.
 */
@Api(tags = "枚举类型Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_COMMON + "/get_enums")
public class EnumsController {

    @Resource
    BasicExamRuleService basicExamRuleService;

    /**
     * 查询
     *
     * @param type
     * @return
     */
    @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 = new ArrayList<>();
        if (type.equals(EnumType.BACKUP_METHOD.name())) {
            //备份方式
            list = BackupMethodEnum.listTypes();
        } else if (type.equals(EnumType.CLASSIFY.name())) {
            //模板类型
            list = ClassifyEnum.listTypes();
        } else if (type.equals(EnumType.DRAW_RULE.name())) {
            // 抽卷规则
            list = DrawRuleEnum.listTypes();
        } else if (type.equals(EnumType.EXAM_NUMBER_STYLE.name())) {
            //考号版式
            list = ExamNumberStyleEnum.listTypes();
        } else if (type.equals(EnumType.EXAM_STATUS.name())) {
            //命题状态类型
            list = ExamStatusEnum.listTypes();
        } else if (type.equals(EnumType.PAPER_TYPE.name())) {
            //AB卷版式
            list = PaperTypeEnum.listTypes();
        } else if (type.equals(EnumType.PRINT_METHOD.name())) {
            //印刷方式
            list = PrintMethodEnum.listTypes();
        } else if (type.equals(EnumType.PRIVILEGE_TYPE.name())) {
            //菜单类型
            list = PrivilegeEnum.listTypes();
        } else if (type.equals(EnumType.REQUIRED_FIELDS.name())) {
            //考务必选字段
//            list = RequiredFieldsEnum.listTypes();
            BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId();
            if (basicExamRule != null) {
                list = JSON.parseArray(basicExamRule.getRequiredFields(), EnumResult.class);
            }
        } else if (type.equals(EnumType.REVIEW_STATUS.name())) {
            //审核状态类型
            list = ReviewStatusEnum.listTypes();
        } else if (type.equals(EnumType.ROLE_TYPE.name())) {
            //内置角色类型
            list = RoleTypeEnum.listTypes(false);
        } else if (type.equals(EnumType.CARD_REQUIRED_FIELDS.name())) {
            //题卡必选字段
            list = CardRequiredFieldsEnum.listTypes();
        } else if (type.equals(EnumType.PRINT_PLAN_STATUS_ENUM.name())) {
            //印刷计划状态
            list = PrintPlanStatusEnum.listTypes();
        } else if (type.equals(EnumType.MAKE_METHOD.name())) {
            // 题卡制作方式
            list = MakeMethodEnum.listTypes();
        } else if (type.equals(EnumType.CARD_TYPE.name())) {
            // 题卡类型
            list = CardTypeEnum.listTypes();
        } else if (type.equals(EnumType.EXAM_DETAIL_STATUS_ENUM.name())) {
            // 考场状态
            list = ExamDetailStatusEnum.listTypes();
        } else if (type.equals(EnumType.SYSTEM_CODE_ENUM.name())) {
            // 系统自生成编码
            list = SystemCodeEnum.listTypes();
        } else if (type.equals(EnumType.PUSH_TYPE_ENUM.name())) {
            // 同步云阅卷类型
            list = PushTypeEnum.listTypes();
        } else if (type.equals(EnumType.TB_TASK_STATUS.name())) {
            // 同步云阅卷日志表状态类型
            list = TaskStatusEnum.listTypes();
        } else if (type.equals(EnumType.CUSTOMIZED_OPERATION_TYPE_ENUM.name())) {
            // 同步云阅卷日志表状态类型
            list = OperationTypeEnum.listTypes();
        } else if (type.equals(EnumType.DATA_PERMISSION_TYPE_ENUM.name())) {
            // 同步云阅卷日志表状态类型
            list = DataPermissionTypeEnum.listTypes();
        } else if (type.equals(EnumType.MARK_PROBLEM_TYPE.name())) {
            // 问题卷类型
            list = MarkProblemType.listTypes();
        } else if (type.equals(EnumType.MARK_ARBITRATE_STATUS.name())) {
            // 仲裁状态
            list = MarkArbitrateStatus.listTypes();
        }
        return ResultUtil.ok(list);
    }
}
