"""Global utility functions for the module"""

from discord import Embed
from eve_sde.models import SolarSystem

from allianceauth.services.hooks import get_extension_logger

logger = get_extension_logger(__name__)


def default_embed(title: str, description: str | None = None) -> Embed:
    """Returns the default embed layout to use accross the app"""
    e = Embed(
        title=title,
        description=description,
    )
    e.set_author(
        name="EVE-scout",
        url="https://eve-scout.com/#/",
        icon_url="https://images.evetech.net/alliances/99005130/logo?size=128",
    )

    return e


def find_solar_system_from_str(solar_system_name: str) -> SolarSystem | None:
    """
    Will attempt to load a system from its name
    """
    logger.debug("Trying to find solar system for name %s", solar_system_name)
    try:
        solar_system = SolarSystem.objects.get(name=solar_system_name)
        return solar_system
    except SolarSystem.DoesNotExist:
        logger.warning(
            "Couldn't find solar system %s",
            solar_system_name,
        )
        return None
