import importlib_metadata
from oarepo_runtime.resources.responses import ExportableResponseHandler
from flask_resources.serializers.json import JSONSerializer
from invenio_records_resources.resources.records.headers import etag_headers
from oarepo_runtime.i18n import lazy_gettext as _
{{ vars.json_serializer.class|imports }}
{{ vars.resource_config|imports }}

class {{ vars.resource_config|class_header }}:
    """{{ vars.record.class|base_name }} resource config."""

    blueprint_name = '{{ vars.api_blueprint.alias }}'
    url_prefix = '{{ vars.resource_config.base_url }}'

    @property
    def response_handlers(self):
        entrypoint_response_handlers = {}
        for x in importlib_metadata.entry_points(group='invenio.{{ vars.module.qualified }}.response_handlers'):
            entrypoint_response_handlers.update(x.load())
        return {
            "application/json": ExportableResponseHandler(export_code="json", name=_("Native JSON"), serializer=JSONSerializer(), headers=etag_headers),
            "application/vnd.inveniordm.v1+json": ExportableResponseHandler(export_code="ui_json", name=_("Native UI JSON"), serializer={{vars.json_serializer.class|base_name}}()),
            **entrypoint_response_handlers
        }

    @property
    def error_handlers(self):
        entrypoint_error_handlers = {}
        for x in importlib_metadata.entry_points(
            group='invenio.{{ vars.module.qualified }}_{{ profile }}.error_handlers'
        ):
            entrypoint_error_handlers.update(x.load())
        return {
            **super().error_handlers,
            **entrypoint_error_handlers
        }

    @property
    def request_body_parsers(self):
        entrypoint_request_bodyparsers = {}
        for x in importlib_metadata.entry_points(
                group="invenio.{{ vars.module.qualified }}_{{ profile }}.request_bodyparsers"
        ):
            entrypoint_request_bodyparsers.update(x.load())
        return {
            **super().request_body_parsers,
            **entrypoint_request_bodyparsers,
        }

{{ vars.resource_config|extra_code }}