package com.codebyte.api.common.error;

import lombok.Getter;
import org.springframework.http.HttpStatus;

/**
 * Stable, machine-readable error codes surfaced in the {@code code} field of every RFC 7807 {@link
 * org.springframework.http.ProblemDetail}. The enum constant name IS the wire code, so it must
 * remain stable even if the human-readable title changes.
 */
@Getter
public enum ErrorCode {
    ITEM_NOT_FOUND(HttpStatus.NOT_FOUND, "Item not found"),
    ITEM_NAME_TAKEN(HttpStatus.CONFLICT, "Item name already in use"),
    ITEM_VERSION_CONFLICT(HttpStatus.CONFLICT, "Item was modified concurrently"),
    TOKEN_INVALID(HttpStatus.BAD_REQUEST, "Token is invalid or has expired"),
    INVALID_CREDENTIALS(HttpStatus.UNAUTHORIZED, "Invalid email or password"),
    ACCOUNT_NOT_ACTIVATED(HttpStatus.FORBIDDEN, "Account is not activated"),
    ACCOUNT_LOCKED(HttpStatus.LOCKED, "Account is temporarily locked"),
    INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "Refresh token is invalid or expired"),
    TOKEN_REUSE_DETECTED(HttpStatus.UNAUTHORIZED, "Refresh token reuse detected"),
    UNAUTHENTICATED(HttpStatus.UNAUTHORIZED, "Authentication required"),
    ACCESS_DENIED(HttpStatus.FORBIDDEN, "Access denied"),
    RATE_LIMITED(HttpStatus.TOO_MANY_REQUESTS, "Too many requests"),
    VALIDATION_FAILED(HttpStatus.BAD_REQUEST, "Request validation failed"),
    MALFORMED_REQUEST(HttpStatus.BAD_REQUEST, "Malformed request"),
    CONSTRAINT_VIOLATION(HttpStatus.BAD_REQUEST, "Constraint violation"),
    INTERNAL_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal server error");

    private final HttpStatus status;
    private final String title;

    ErrorCode(HttpStatus status, String title) {
        this.status = status;
        this.title = title;
    }
}
