from core.logger import DBLogger
from data.abc.data_seeder_abc import DataSeederABC
from data.schemas.public.group import Group
from data.schemas.public.group_dao import groupDao
from data.schemas.public.short_url import ShortUrl
from data.schemas.public.short_url_dao import shortUrlDao

logger = DBLogger(__name__)


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

    async def seed(self):
        if await groupDao.count() == 0:
            default_id = await groupDao.create(Group(0, "default"))
        else:
            default_id = (await groupDao.get_single_by({Group.name: "default"})).id

        if await shortUrlDao.count() == 0:
            await shortUrlDao.create(
                ShortUrl(0, "sh-edraft", "https://sh-edraft.de", "default", default_id)
            )
