from django.db import models


class SiteSettings(models.Model):
    """
    Singleton model — only one row ever exists.
    Controls all branding, contact info, social links, SMTP, and site-wide settings.
    """
    site_name    = models.CharField(max_length=100, default='Villaco Real Estate')
    site_tagline = models.CharField(max_length=200, default='Your Trusted Property Partner in Nigeria')
    rc_number    = models.CharField(max_length=50, blank=True, default='RC: 8343179', help_text='Company Registration Number')
    favicon      = models.ImageField(upload_to='site/', blank=True, null=True)

    # ── Contact ──────────────────────────────────────────────────────────
    email = models.EmailField(blank=True)
    notification_emails = models.TextField(
        blank=True,
        help_text='Personal email(s) to notify on every enquiry. Separate multiple emails with commas.'
    )
    phone_1  = models.CharField(max_length=20, blank=True)
    phone_2  = models.CharField(max_length=20, blank=True)
    whatsapp = models.CharField(max_length=20, blank=True, help_text='Number with country code, e.g. 2348012345678')
    address  = models.TextField(blank=True)

    # ── Social ────────────────────────────────────────────────────────────
    facebook_url  = models.URLField(blank=True)
    instagram_url = models.URLField(blank=True)
    twitter_url   = models.URLField(blank=True)
    linkedin_url  = models.URLField(blank=True)
    youtube_url   = models.URLField(blank=True)

    # ── Footer & Map ──────────────────────────────────────────────────────
    footer_text       = models.CharField(max_length=300, blank=True)
    google_maps_embed = models.TextField(blank=True, help_text='Paste the Google Maps embed iframe code here')

    # ── SEO Fallbacks ─────────────────────────────────────────────────────
    meta_title       = models.CharField(max_length=160, blank=True)
    meta_description = models.CharField(max_length=300, blank=True)

    class Meta:
        verbose_name        = 'Site Settings'
        verbose_name_plural = 'Site Settings'

    def __str__(self):
        return self.site_name

    def save(self, *args, **kwargs):
        self.pk = 1  # Enforce singleton
        super().save(*args, **kwargs)

    @classmethod
    def get(cls):
        obj, _ = cls.objects.get_or_create(pk=1)
        return obj
