from typing import Optional, Union

from fastapi.responses import JSONResponse

def success_response(data: Union[dict, list, str, None] = None, message: Optional[str] = None, status_code: int = 200, success: bool = True):
    return JSONResponse(status_code=status_code, content={
        "success": success,
        "message": message,
        "error": None,
        "data": data
    })

def error_response(error: Union[str, Exception, dict, list, None]=None, message: Optional[str] = None, status_code: int = 500):

        
    if isinstance(error, dict):
        return JSONResponse(status_code=status_code, content={
            "success": False,
            "data": error,
            "message": message,
            "data": None
        })
    return JSONResponse(status_code=status_code, content={
            "success": False,
            "data": str(error),
            "message": message,
            "data": None
        })