package com.qqchen.deploy.backend.framework.enums;

import lombok.Getter;

@Getter
public enum ResponseCode {
    SUCCESS(200, "response.success"),
    ERROR(500, "response.error"),
    INVALID_PARAM(400, "response.invalid.param"),
    UNAUTHORIZED(401, "response.unauthorized"),
    AUTH_REQUIRED(401, "response.unauthorized.full"),
    FORBIDDEN(403, "response.forbidden"),
    NOT_FOUND(404, "response.not.found"),
    CONFLICT(409, "response.conflict"),

    // 系统异常 (1开头)
    OPTIMISTIC_LOCK_ERROR(1001, "system.optimistic.lock.error"),    // 乐观锁异常
    PESSIMISTIC_LOCK_ERROR(1002, "system.pessimistic.lock.error"),  // 悲观锁异常
    CONCURRENT_UPDATE_ERROR(1003, "system.concurrent.update.error"), // 并发更新异常
    RETRY_EXCEEDED_ERROR(1004, "system.retry.exceeded.error"),      // 重试次数超限异常

    // 依赖注入相关错误 (1100-1199)
    DEPENDENCY_INJECTION_SERVICE_NOT_FOUND(1100, "dependency.injection.service.not.found"),
    DEPENDENCY_INJECTION_REPOSITORY_NOT_FOUND(1101, "dependency.injection.repository.not.found"),
    DEPENDENCY_INJECTION_CONVERTER_NOT_FOUND(1102, "dependency.injection.converter.not.found"),
    DEPENDENCY_INJECTION_ENTITYPATH_FAILED(1103, "dependency.injection.entitypath.failed"),

    // 业务异常 (2开头)
    TENANT_NOT_FOUND(2001, "tenant.not.found"),
    DATA_NOT_FOUND(2002, "data.not.found"),
    USER_NOT_FOUND(2003, "user.not.found"),
    USERNAME_EXISTS(2004, "user.username.exists"),
    EMAIL_EXISTS(2005, "user.email.exists"),
    LOGIN_ERROR(2006, "user.login.error"),

    // 角色相关错误码 (2100-2199)
    ROLE_NOT_FOUND(2100, "role.not.found"),
    ROLE_CODE_EXISTS(2101, "role.code.exists"),
    ROLE_NAME_EXISTS(2102, "role.name.exists"),
    ROLE_IN_USE(2103, "role.in.use"),
    ROLE_ADMIN_CANNOT_DELETE(2104, "role.admin.cannot.delete"),
    ROLE_ADMIN_CANNOT_UPDATE(2105, "role.admin.cannot.update"),

    // JWT相关错误码 (2200-2299)
    JWT_EXPIRED(2200, "jwt.token.expired"),
    JWT_INVALID(2201, "jwt.token.invalid"),
    JWT_MISSING(2202, "jwt.token.missing"),

    // 角色标签相关错误码 (4300-4399)
    ROLE_TAG_NAME_EXISTS(4300, "role.tag.name.exists"),
    ROLE_TAG_NOT_FOUND(4301, "role.tag.not.found"),
    ROLE_TAG_IN_USE(4302, "role.tag.in.use"),

    // 部门相关错误码 (2300-2399)
    DEPARTMENT_NOT_FOUND(2300, "department.not.found"),
    DEPARTMENT_CODE_EXISTS(2301, "department.code.exists"),
    DEPARTMENT_NAME_EXISTS(2302, "department.name.exists"),
    DEPARTMENT_PARENT_NOT_FOUND(2303, "department.parent.not.found"),
    DEPARTMENT_HAS_CHILDREN(2304, "department.has.children"),

    // 权限相关错误码 (2400-2499)
    PERMISSION_NOT_FOUND(2400, "permission.not.found"),
    PERMISSION_CODE_EXISTS(2401, "permission.code.exists"),
    PERMISSION_NAME_EXISTS(2402, "permission.name.exists"),
    PERMISSION_ALREADY_ASSIGNED(2403, "permission.already.assigned"),
    PERMISSION_ASSIGN_FAILED(2404, "permission.assign.failed"),

    // 第三方系统相关错误码 (2500-2599)
    EXTERNAL_SYSTEM_NOT_FOUND(2505, "external.system.not.found"),
    EXTERNAL_SYSTEM_NAME_EXISTS(2500, "external.system.name.exists"),
    EXTERNAL_SYSTEM_TYPE_URL_EXISTS(2501, "external.system.type.url.exists"),
    EXTERNAL_SYSTEM_DISABLED(2502, "external.system.disabled"),
    EXTERNAL_SYSTEM_SYNC_FAILED(2503, "external.system.sync.failed"),
    EXTERNAL_SYSTEM_TYPE_NOT_SUPPORTED(2504, "external.system.type.not.supported"),

    // Git系统相关错误码
    EXTERNAL_SYSTEM_GIT_AUTH_TYPE_ERROR(2501, "Git系统只支持Token认证"),
    EXTERNAL_SYSTEM_GIT_TOKEN_REQUIRED(2502, "Git系统必须提供Token"),

    // 仓库相关错误码 (2600-2699)
    REPOSITORY_GROUP_NOT_FOUND(2600, "repository.group.not.found"),
    REPOSITORY_GROUP_SYNC_FAILED(2601, "repository.group.sync.failed"),
    REPOSITORY_GROUP_PATH_EXISTS(2602, "repository.group.path.exists"),
    REPOSITORY_PROJECT_NOT_FOUND(2610, "repository.project.not.found"),
    REPOSITORY_PROJECT_SYNC_FAILED(2611, "repository.project.sync.failed"),
    REPOSITORY_PROJECT_PATH_EXISTS(2612, "repository.project.path.exists"),
    REPOSITORY_BRANCH_NOT_FOUND(2620, "repository.branch.not.found"),
    REPOSITORY_BRANCH_SYNC_FAILED(2621, "repository.branch.sync.failed"),
    REPOSITORY_SYNC_IN_PROGRESS(2630, "repository.sync.in.progress"),
    REPOSITORY_SYNC_FAILED(2631, "repository.sync.failed"),
    REPOSITORY_SYNC_HISTORY_NOT_FOUND(2632, "repository.sync.history.not.found"),

    // 工作流相关错误码 (2700-2799)
    WORKFLOW_NOT_FOUND(2700, "workflow.not.found"),
    WORKFLOW_CODE_EXISTS(2701, "workflow.code.exists"),
    WORKFLOW_NAME_EXISTS(2702, "workflow.name.exists"),
    WORKFLOW_DISABLED(2703, "workflow.disabled"),
    WORKFLOW_NOT_PUBLISHED(2704, "workflow.not.published"),
    WORKFLOW_ALREADY_PUBLISHED(2705, "workflow.already.published"),
    WORKFLOW_ALREADY_DISABLED(2706, "workflow.already.disabled"),
    WORKFLOW_NOT_DRAFT(2707, "workflow.not.draft"),
    WORKFLOW_NOT_DISABLED(2708, "workflow.not.disabled"),
    WORKFLOW_INVALID_STATUS(2709, "workflow.invalid.status"),
    WORKFLOW_INSTANCE_NOT_FOUND(2710, "workflow.instance.not.found"),
    WORKFLOW_INSTANCE_ALREADY_COMPLETED(2711, "workflow.instance.already.completed"),
    WORKFLOW_INSTANCE_ALREADY_CANCELED(2712, "workflow.instance.already.canceled"),
    WORKFLOW_INSTANCE_NOT_RUNNING(2713, "workflow.instance.not.running"),
    WORKFLOW_INSTANCE_NOT_PAUSED(2714, "workflow.instance.not.paused"),
    WORKFLOW_NODE_NOT_FOUND(2720, "workflow.node.not.found"),
    WORKFLOW_NODE_TYPE_NOT_SUPPORTED(2721, "workflow.node.type.not.supported"),
    WORKFLOW_NODE_CONFIG_INVALID(2722, "workflow.node.config.invalid"),
    WORKFLOW_NODE_EXECUTION_FAILED(2723, "workflow.node.execution.failed"),
    WORKFLOW_NODE_TIMEOUT(2724, "workflow.node.timeout"),
    WORKFLOW_NODE_CONFIG_ERROR(2725, "workflow.node.config.error"),
    WORKFLOW_EXECUTION_ERROR(2726, "workflow.execution.error"),
    WORKFLOW_CONFIG_ERROR(2727, "workflow.config.error"),
    WORKFLOW_VARIABLE_NOT_FOUND(2730, "workflow.variable.not.found"),
    WORKFLOW_VARIABLE_TYPE_INVALID(2731, "workflow.variable.type.invalid"),
    WORKFLOW_PERMISSION_DENIED(2740, "workflow.permission.denied"),
    WORKFLOW_APPROVAL_REQUIRED(2741, "workflow.approval.required"),
    WORKFLOW_APPROVAL_REJECTED(2742, "workflow.approval.rejected"),
    WORKFLOW_DEPENDENCY_NOT_SATISFIED(2750, "workflow.dependency.not.satisfied"),
    WORKFLOW_CIRCULAR_DEPENDENCY(2751, "workflow.circular.dependency"),
    WORKFLOW_SCHEDULE_INVALID(2752, "workflow.schedule.invalid"),
    WORKFLOW_CONCURRENT_LIMIT_EXCEEDED(2753, "workflow.concurrent.limit.exceeded"),
    WORKFLOW_CONFIG_INVALID(2754, "workflow.config.invalid"),
    WORKFLOW_TRANSITION_INVALID(2755, "workflow.transition.invalid"),
    WORKFLOW_CONDITION_INVALID(2756, "workflow.condition.invalid"),

    // 工作流配置相关错误码 (2760-2769)
    WORKFLOW_NODE_CONFIG_EMPTY(2760, "workflow.node.config.empty"),
    WORKFLOW_TRANSITION_CONFIG_EMPTY(2761, "workflow.transition.config.empty"),
    WORKFLOW_FORM_CONFIG_EMPTY(2762, "workflow.form.config.empty"),
    WORKFLOW_GRAPH_CONFIG_EMPTY(2763, "workflow.graph.config.empty"),

    // 2200-2299 工作流节点类型错误
    WORKFLOW_NODE_TYPE_NOT_FOUND(2200, "workflow.node.type.not.found"),
    WORKFLOW_NODE_TYPE_DISABLED(2201, "workflow.node.type.disabled"),
    WORKFLOW_NODE_TYPE_CODE_EXISTS(2202, "workflow.node.type.code.exists"),
    WORKFLOW_NODE_TYPE_INVALID_CATEGORY(2203, "workflow.node.type.invalid.category"),
    WORKFLOW_NODE_TYPE_INVALID_EXECUTOR(2204, "workflow.node.type.invalid.executor"),
    WORKFLOW_NODE_EXECUTOR_NOT_FOUND(2205, "workflow.node.executor.not.found"),

    /**
     * 工作流变量序列化错误
     */
    WORKFLOW_VARIABLE_SERIALIZE_ERROR(50301, "workflow.variable.serialize.error"),

    /**
     * 工作流变量反序列化错误
     */
    WORKFLOW_VARIABLE_DESERIALIZE_ERROR(50302, "workflow.variable.deserialize.error"),

    // 表单管理相关错误码 (2800-2899)
    FORM_DEFINITION_NOT_FOUND(2800, "form.definition.not.found"),
    FORM_DATA_NOT_FOUND(2801, "form.data.not.found");

    private final int code;
    private final String messageKey;  // 国际化消息key

    ResponseCode(int code, String messageKey) {
        this.code = code;
        this.messageKey = messageKey;
    }
}