from typing import Any

from core.logger import DBLogger
from data.abc.data_seeder_abc import DataSeederABC
from data.schemas.system.setting import Setting
from data.schemas.system.setting_dao import settingDao

logger = DBLogger(__name__)


class SettingsSeeder(DataSeederABC):
    def __init__(self):
        DataSeederABC.__init__(self)

    async def seed(self):
        await self._seed_if_not_exists("default_language", "de")
        await self._seed_if_not_exists("show_terms", True)

    @staticmethod
    async def _seed_if_not_exists(key: str, value: Any):
        existing = await settingDao.find_by_key(key)
        if existing is not None:
            return

        await settingDao.create(Setting(0, key, str(value)))
