from typing import Any

from flask.json import JSONEncoder as Base

from pycs.database.base import BaseModel

class JSONEncoder(Base):
    """
    prepares database objects to be json encoded
    """

    def default(self, o: Any) -> Any:
        if isinstance(o, BaseModel):
            return o.serialize()

        return o.__dict__.copy()
