from django.urls import path

from ocyan.core.plugins import OcyanPluginConfig


class MobileAppConfig(OcyanPluginConfig):
    def contribute_to_installed_apps(self, installed_apps):
        installed_apps.ocyan.append("ocyan.plugin.mobileapp")
        return installed_apps

    def contribute_to_urlpatterns(self, urlpatterns):
        from .views import ManifestView, OfflineFallbackView, ServiceWorkerView

        new_patterns = [
            path("manifest.json", ManifestView.as_view(), name="manifest_json"),
            path(
                "serviceworker.js",
                ServiceWorkerView.as_view(),
                name="mobileapp_serviceworker",
            ),
            path("offline/", OfflineFallbackView.as_view(), name="mobileapp_offline"),
        ]
        new_patterns.extend(list(urlpatterns))
        return new_patterns
