from django.db import models

from apps.common.models import OrderedModel, SingletonModel


class SiteSettings(SingletonModel):
    """Coordonnées et identité du site. Une seule ligne (pk=1)."""

    name = models.CharField("nom", max_length=100, default="Ceder Consulting")
    tagline = models.CharField("slogan", max_length=200, blank=True)
    description = models.CharField("description SEO par défaut", max_length=160, blank=True)
    phone = models.CharField("téléphone", max_length=30, blank=True)
    phone_secondary = models.CharField("second téléphone", max_length=30, blank=True)
    whatsapp = models.CharField("WhatsApp", max_length=30, blank=True, help_text="Format +237…")
    email = models.EmailField("email", blank=True)
    address = models.CharField("adresse", max_length=255, blank=True)
    city = models.CharField("ville", max_length=100, default="Douala")
    country = models.CharField("pays", max_length=100, default="Cameroun")
    latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
    longitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
    opening_hours = models.CharField("horaires", max_length=255, blank=True)
    logo = models.ImageField("logo", upload_to="site/", blank=True)

    class Meta:
        verbose_name = verbose_name_plural = "réglages du site"

    def __str__(self) -> str:
        return self.name


class SocialLink(OrderedModel):
    NETWORKS = [
        ("facebook", "Facebook"),
        ("linkedin", "LinkedIn"),
        ("instagram", "Instagram"),
        ("x", "X (Twitter)"),
        ("youtube", "YouTube"),
        ("tiktok", "TikTok"),
    ]
    settings = models.ForeignKey(
        SiteSettings, on_delete=models.CASCADE, related_name="social_links"
    )
    network = models.CharField("réseau", max_length=20, choices=NETWORKS)
    url = models.URLField("lien")

    class Meta(OrderedModel.Meta):
        verbose_name = "réseau social"
        verbose_name_plural = "réseaux sociaux"

    def __str__(self) -> str:
        return self.get_network_display()
