"""Custom Flask JSON provider using orjson for faster serialization."""

import orjson
from flask.json.provider import DefaultJSONProvider


class OrjsonProvider(DefaultJSONProvider):
    """Drop-in replacement for Flask's default JSON provider using orjson."""

    def dumps(self, obj, **kwargs):
        # Remove Flask-specific kwargs that orjson doesn't understand
        # (indent, separators, sort_keys are not used by orjson in the same way)
        # orjson returns bytes; decode to str for Flask
        return orjson.dumps(obj, default=str).decode('utf-8')

    def loads(self, s, **kwargs):
        return orjson.loads(s)
