"""Standard response utilities.""" from typing import Any from fastapi import status class ErrorResponse: """Standard error response formats.""" @staticmethod def not_found(resource: str = "Resource") -> dict[str, Any]: """404 Not Found response.""" return { "status_code": status.HTTP_404_NOT_FOUND, "detail": f"{resource} not found", } @staticmethod def forbidden(message: str = "Access denied") -> dict[str, Any]: """403 Forbidden response.""" return { "status_code": status.HTTP_403_FORBIDDEN, "detail": message, } @staticmethod def unauthorized(message: str = "Authentication required") -> dict[str, Any]: """401 Unauthorized response.""" return { "status_code": status.HTTP_401_UNAUTHORIZED, "detail": message, "headers": {"WWW-Authenticate": "Bearer"}, } @staticmethod def bad_request(message: str) -> dict[str, Any]: """400 Bad Request response.""" return { "status_code": status.HTTP_400_BAD_REQUEST, "detail": message, } @staticmethod def conflict(message: str) -> dict[str, Any]: """409 Conflict response.""" return { "status_code": status.HTTP_409_CONFLICT, "detail": message, } class SuccessResponse: """Standard success response formats.""" @staticmethod def created(data: dict[str, Any], message: str = "Created successfully") -> dict[str, Any]: """201 Created response.""" return { "message": message, "data": data, } @staticmethod def ok(data: dict[str, Any] | None = None, message: str = "Success") -> dict[str, Any]: """200 OK response.""" response = {"message": message} if data: response["data"] = data return response @staticmethod def no_content() -> None: """204 No Content response.""" return None