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"),
    
    // SSH文件操作相关错误 (1200-1299)
    SSH_FILE_CONNECTION_FAILED(1200, "ssh.file.connection.failed"),
    SSH_FILE_AUTHENTICATION_FAILED(1201, "ssh.file.authentication.failed"),
    SSH_FILE_NOT_FOUND(1202, "ssh.file.not.found"),
    SSH_FILE_DIRECTORY_NOT_FOUND(1203, "ssh.file.directory.not.found"),
    SSH_FILE_PERMISSION_DENIED(1204, "ssh.file.permission.denied"),
    SSH_FILE_DISK_FULL(1205, "ssh.file.disk.full"),
    SSH_FILE_INVALID_PATH(1206, "ssh.file.invalid.path"),
    SSH_FILE_ALREADY_EXISTS(1207, "ssh.file.already.exists"),
    SSH_FILE_TOO_LARGE(1208, "ssh.file.too.large"),
    SSH_FILE_UNSUPPORTED_TYPE(1209, "ssh.file.unsupported.type"),
    SSH_FILE_IO_ERROR(1210, "ssh.file.io.error"),
    SSH_FILE_TIMEOUT(1211, "ssh.file.timeout"),
    SSH_FILE_OPERATION_FAILED(1212, "ssh.file.operation.failed"),
    SSH_FILE_UPLOAD_SIZE_EXCEEDED(1213, "ssh.file.upload.size.exceeded"),
    SSH_FILE_UPLOAD_CANCELLED(1214, "ssh.file.upload.cancelled"),

    // 业务异常 (2开头)
    TENANT_NOT_FOUND(2001, "tenant.not.found"),
    DATA_NOT_FOUND(2002, "data.not.found"),
    DATA_ALREADY_EXISTS(2003, "data.already.exists"),
    DATA_IN_USE(2004, "data.in.use"),
    USER_NOT_FOUND(2005, "user.not.found"),
    USERNAME_EXISTS(2006, "user.username.exists"),
    EMAIL_EXISTS(2007, "user.email.exists"),
    LOGIN_ERROR(2008, "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"),
    PERMISSION_DENIED(2405, "permission.denied"),

    // 第三方系统相关错误码 (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"),
    WORKFLOW_FORM_NOT_BOUND(2764, "workflow.form.not.bound"),

    // 定时任务相关错误码 (2800-2899)
    SCHEDULE_JOB_NOT_FOUND(2800, "schedule.job.not.found"),
    SCHEDULE_JOB_NAME_EXISTS(2801, "schedule.job.name.exists"),
    SCHEDULE_JOB_START_FAILED(2802, "schedule.job.start.failed"),
    SCHEDULE_JOB_PAUSE_FAILED(2803, "schedule.job.pause.failed"),
    SCHEDULE_JOB_RESUME_FAILED(2804, "schedule.job.resume.failed"),
    SCHEDULE_JOB_DISABLE_FAILED(2805, "schedule.job.disable.failed"),
    SCHEDULE_JOB_TRIGGER_FAILED(2806, "schedule.job.trigger.failed"),
    SCHEDULE_JOB_UPDATE_CRON_FAILED(2807, "schedule.job.update.cron.failed"),
    SCHEDULE_JOB_CRON_INVALID(2808, "schedule.job.cron.invalid"),
    SCHEDULE_JOB_BEAN_NOT_FOUND(2809, "schedule.job.bean.not.found"),
    SCHEDULE_JOB_METHOD_NOT_FOUND(2810, "schedule.job.method.not.found"),
    SCHEDULE_JOB_TRIGGER_NOT_FOUND(2811, "schedule.job.trigger.not.found"),
    SCHEDULE_JOB_ALREADY_RUNNING(2812, "schedule.job.already.running"),
    SCHEDULE_JOB_NOT_RUNNING(2813, "schedule.job.not.running"),
    SCHEDULE_JOB_STATUS_CANNOT_UPDATE(2814, "schedule.job.status.cannot.update"),
    SCHEDULE_JOB_DISABLED_CANNOT_TRIGGER(2815, "schedule.job.disabled.cannot.trigger"),
    SCHEDULE_JOB_UPDATE_FAILED(2816, "schedule.job.update.failed"),
    SCHEDULE_JOB_CATEGORY_NOT_FOUND(2820, "schedule.job.category.not.found"),
    SCHEDULE_JOB_CATEGORY_CODE_EXISTS(2821, "schedule.job.category.code.exists"),
    SCHEDULE_JOB_CATEGORY_HAS_JOBS(2822, "schedule.job.category.has.jobs"),
    SCHEDULE_JOB_CATEGORY_IN_USE(2823, "schedule.job.category.in.use"),
    SCHEDULE_JOB_LOG_NOT_FOUND(2830, "schedule.job.log.not.found"),
    SCHEDULE_JOB_EXECUTOR_NOT_FOUND(2831, "schedule.job.executor.not.found"),

    // 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-2819)
    FORM_DEFINITION_NOT_FOUND(2800, "form.definition.not.found"),
    FORM_DATA_NOT_FOUND(2801, "form.data.not.found"),
    FORM_DEFINITION_KEY_EXISTS(2802, "form.definition.key.exists"),
    FORM_DEFINITION_KEY_VERSION_EXISTS(2803, "form.definition.key.version.exists"),

    // 环境管理相关错误码 (2880-2899)
    ENVIRONMENT_NOT_FOUND(2880, "environment.not.found"),
    ENVIRONMENT_CODE_EXISTS(2881, "environment.code.exists"),
    ENVIRONMENT_HAS_TEAMS(2882, "environment.has.teams"),

    // 应用分类相关错误码 (2900-2919)
    APPLICATION_CATEGORY_NOT_FOUND(2900, "application.category.not.found"),
    APPLICATION_CATEGORY_CODE_EXISTS(2901, "application.category.code.exists"),
    APPLICATION_CATEGORY_HAS_APPLICATIONS(2902, "application.category.has.applications"),
    APPLICATION_HAS_TEAMS(2903, "application.has.teams"),

    // 团队管理相关错误码 (2920-2949)
    TEAM_NOT_FOUND(2920, "team.not.found"),
    TEAM_CODE_EXISTS(2921, "team.code.exists"),
    TEAM_HAS_MEMBERS(2922, "team.has.members"),
    TEAM_HAS_APPLICATIONS(2923, "team.has.applications"),
    TEAM_ENVIRONMENT_HAS_APPLICATIONS(2924, "team.environment.has.applications"),
    TEAM_MEMBER_NOT_FOUND(2925, "team.member.not.found"),
    TEAM_MEMBER_ALREADY_EXISTS(2926, "team.member.already.exists"),
    TEAM_APPLICATION_NOT_FOUND(2927, "team.application.not.found"),
    TEAM_APPLICATION_ALREADY_EXISTS(2928, "team.application.already.exists"),
    TEAM_CONFIG_NOT_FOUND(2929, "team.config.not.found"),
    TEAM_APPLICATION_DEPLOY_JOB_EXISTS(2930, "team.application.deploy.job.exists"),

    // 服务器管理相关错误码 (2950-2969)
    SERVER_NOT_FOUND(2950, "server.not.found"),
    SERVER_IP_EXISTS(2951, "server.ip.exists"),
    SERVER_CATEGORY_NOT_FOUND(2952, "server.category.not.found"),
    SERVER_CATEGORY_CODE_EXISTS(2953, "server.category.code.exists"),
    SERVER_CATEGORY_HAS_SERVERS(2954, "server.category.has.servers"),

    // 部署相关错误码 (3000-3099)
    DEPLOY_CONFIG_NOT_FOUND(3000, "deploy.config.not.found"),
    DEPLOY_APPROVAL_CONFIG_MISSING(3001, "deploy.approval.config.missing"),
    DEPLOY_APPROVER_NOT_CONFIGURED(3002, "deploy.approver.not.configured"),
    DEPLOY_NOTIFICATION_CONFIG_MISSING(3003, "deploy.notification.config.missing"),
    DEPLOY_JENKINS_CONFIG_MISSING(3004, "deploy.jenkins.config.missing"),
    DEPLOY_WORKFLOW_NOT_CONFIGURED(3005, "deploy.workflow.not.configured"),
    DEPLOY_ENVIRONMENT_CONFIG_MISSING(3006, "deploy.environment.config.missing"),
    DEPLOY_APPLICATION_NOT_CONFIGURED(3007, "deploy.application.not.configured"),
    DEPLOY_ALREADY_RUNNING(3008, "deploy.already.running"),
    DEPLOY_PERMISSION_DENIED(3009, "deploy.permission.denied"),
    DEPLOY_ENVIRONMENT_LOCKED(3010, "deploy.environment.locked"),
    DEPLOY_APPROVAL_REQUIRED(3011, "deploy.approval.required"),
    DEPLOY_RECORD_NOT_FOUND(3012, "deploy.record.not.found"),

    // 通知模板相关错误码 (3100-3119)
    NOTIFICATION_TEMPLATE_NOT_FOUND(3100, "notification.template.not.found"),
    NOTIFICATION_TEMPLATE_CODE_EXISTS(3101, "notification.template.code.exists"),
    NOTIFICATION_TEMPLATE_DISABLED(3102, "notification.template.disabled"),
    NOTIFICATION_TEMPLATE_RENDER_ERROR(3103, "notification.template.render.error"),
    
    // 通知渠道相关错误码 (3120-3139)
    NOTIFICATION_CHANNEL_NOT_FOUND(3120, "notification.channel.not.found"),
    NOTIFICATION_CHANNEL_DISABLED(3121, "notification.channel.disabled"),
    NOTIFICATION_CHANNEL_CONFIG_ERROR(3122, "notification.channel.config.error"),
    NOTIFICATION_SEND_FAILED(3123, "notification.send.failed"),
    
    // Jenkins集成错误码 (3200-3219)
    JENKINS_SERVER_NOT_FOUND(3200, "jenkins.server.not.found"),
    JENKINS_CONNECTION_FAILED(3201, "jenkins.connection.failed"),
    JENKINS_AUTH_FAILED(3202, "jenkins.auth.failed"),
    JENKINS_JOB_NOT_FOUND(3203, "jenkins.job.not.found"),
    JENKINS_SERVER_ERROR(3204, "jenkins.server.error"),
    JENKINS_QUEUE_TIMEOUT(3205, "jenkins.queue.timeout"),
    JENKINS_BUILD_TIMEOUT(3206, "jenkins.build.timeout"),
    JENKINS_API_ERROR(3207, "jenkins.api.error"),
    JENKINS_RESPONSE_PARSE_ERROR(3208, "jenkins.response.parse.error");

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

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