package com.lesingle.creation.common.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 统一错误码枚举
 *
 * @author lesingle
 * @since 1.0.0
 */
@Getter
@AllArgsConstructor
public enum ErrorCode {

    // ========== 成功 ==========
    SUCCESS(200, "操作成功"),

    // ========== 客户端错误（4xx） ==========
    BAD_REQUEST(400, "请求参数错误"),
    UNAUTHORIZED(401, "未登录或 Token 已过期"),
    FORBIDDEN(403, "没有访问权限"),
    NOT_FOUND(404, "资源不存在"),
    METHOD_NOT_ALLOWED(405, "请求方法不支持"),
    CONFLICT(409, "资源冲突"),

    // ========== 服务端错误（5xx） ==========
    INTERNAL_ERROR(500, "系统内部错误"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),

    // ========== 业务错误（1xxx） ==========
    USER_NOT_FOUND(1001, "用户不存在"),
    USER_ACCOUNT_LOCKED(1002, "用户账号已被锁定"),
    USER_PASSWORD_ERROR(1003, "用户名或密码错误"),
    USER_ALREADY_EXISTS(1004, "用户已存在"),

    ROLE_NOT_FOUND(1101, "角色不存在"),
    ROLE_ALREADY_EXISTS(1102, "角色已存在"),

    PERMISSION_DENIED(1201, "权限不足"),
    PERMISSION_NOT_FOUND(1202, "权限不存在"),

    TOKEN_INVALID(1301, "Token 无效"),
    TOKEN_EXPIRED(1302, "Token 已过期"),

    DATA_NOT_FOUND(1401, "数据不存在"),
    DATA_ALREADY_EXISTS(1402, "数据已存在"),
    DATA_VERSION_ERROR(1403, "数据版本冲突"),

    PARAMS_ERROR(1501, "参数校验失败"),
    FILE_UPLOAD_ERROR(1502, "文件上传失败"),
    FILE_DOWNLOAD_ERROR(1503, "文件下载失败"),
    FILE_NOT_FOUND(1504, "文件不存在"),

    // ========== 数据库错误（2xxx） ==========
    DB_ERROR(2001, "数据库操作失败"),
    DB_CONNECTION_ERROR(2002, "数据库连接失败"),
    DB_QUERY_ERROR(2003, "数据库查询失败"),
    DB_UPDATE_ERROR(2004, "数据库更新失败"),
    DB_DELETE_ERROR(2005, "数据库删除失败"),
    DB_INSERT_ERROR(2006, "数据库插入失败"),

    // ========== 竞赛业务错误（3xxx） ==========
    CONTEST_NOT_FOUND(3001, "竞赛不存在"),
    CONTEST_ALREADY_PUBLISHED(3002, "竞赛已发布"),
    CONTEST_NOT_STARTED(3003, "竞赛未开始"),
    CONTEST_ALREADY_FINISHED(3004, "竞赛已结束"),
    CONTEST_NAME_DUPLICATE(3005, "竞赛名称已存在"),

    REGISTRATION_NOT_FOUND(3101, "报名记录不存在"),
    REGISTRATION_ALREADY_EXISTS(3102, "已报名，不能重复报名"),
    REGISTRATION_AUDIT_PENDING(3103, "报名待审核"),
    REGISTRATION_CLOSED(3104, "报名已截止"),
    REGISTRATION_NOT_ALLOWED(3105, "不允许报名"),

    WORK_NOT_FOUND(3201, "作品不存在"),
    WORK_SUBMISSION_CLOSED(3202, "作品提交已截止"),
    WORK_ALREADY_SUBMITTED(3203, "作品已提交"),
    WORK_NOT_LATEST_VERSION(3204, "不是最新版本"),

    REVIEW_NOT_ASSIGNED(3301, "未分配评审任务"),
    REVIEW_ALREADY_SCORED(3302, "已评分，不能重复评分"),
    REVIEW_SCORE_INVALID(3303, "评分无效"),
    REVIEW_NOT_STARTED(3304, "评审未开始"),

    TEAM_NOT_FOUND(3401, "团队不存在"),
    TEAM_MEMBER_FULL(3402, "团队成员已满"),
    TEAM_MEMBER_DUPLICATE(3403, "用户已在团队中"),

    JUDGE_NOT_FOUND(3501, "评委不存在"),
    JUDGE_ALREADY_ASSIGNED(3502, "评委已分配"),

    AWARD_NOT_FOUND(3601, "奖项不存在"),
    AWARD_ALREADY_SET(3602, "奖项已设置"),

    NOTICE_NOT_FOUND(3701, "公告不存在"),

    // ========== 学校业务错误（4xxx） ==========
    SCHOOL_NOT_FOUND(4001, "学校不存在"),
    SCHOOL_CODE_DUPLICATE(4002, "学校编码已存在"),

    GRADE_NOT_FOUND(4101, "年级不存在"),
    GRADE_DUPLICATE(4102, "年级名称已存在"),

    CLASS_NOT_FOUND(4201, "班级不存在"),
    CLASS_DUPLICATE(4202, "班级名称已存在"),

    TEACHER_NOT_FOUND(4301, "教师不存在"),
    STUDENT_NOT_FOUND(4401, "学生不存在");

    /**
     * 错误码
     */
    private final Integer code;

    /**
     * 错误消息
     */
    private final String message;

}
