# -*- coding: utf-8 -*-
import os

from ocyan.core.plugins import OcyanPluginConfig
from ocyan.core.utils import merge_dicts


class CoyoteConfig(OcyanPluginConfig):
    def contribute_to_installed_apps(self, installed_apps):
        installed_apps.wagtail.append("ocyan.plugin.coyote")
        installed_apps.front.register_extension(
            "ocyan.plugin.coyote.theme_extension", "oxyan.themes"
        )
        installed_apps.front.register_extension(
            "ocyan.plugin.coyote.theme_extension", "ocyan.plugin.barebone"
        )
        return installed_apps

    def contribute_to_settings(self, settings):
        SETTINGS = {
            "COMPRESS_CACHE_KEY_FUNCTION": "ocyan.plugin.coyote.utils.get_compressor_cache_key",
            "OXYAN_LAZY_THEME_DEFINITIONS": "ocyan.plugin.coyote.definitions.get_coyote_definitions",
        }
        if google_fonts_api_key := os.environ.get("GOOGLE_FONTS_API_KEY"):
            SETTINGS["GOOGLE_FONTS_API_KEY"] = google_fonts_api_key

        DEFAULTS = {
            "OXYAN_HEADER_OPTIONS": [],
        }

        # Merge settings with override, and add defaults without override
        return merge_dicts(
            merge_dicts(settings, SETTINGS, overwrite=True),
            DEFAULTS,
            overwrite=False,
        )
