﻿from django.db import models


class TeamMember(models.Model):
    name = models.CharField(max_length=120)
    role = models.CharField(max_length=160)
    bio = models.TextField()
    image = models.ImageField(upload_to='team/', blank=True)
    tiktok_url = models.URLField(blank=True)
    instagram_url = models.URLField(blank=True)
    twitter_url = models.URLField(blank=True)
    linkedin_url = models.URLField(blank=True)
    email = models.EmailField(blank=True)
    sort_order = models.PositiveIntegerField(default=0)
    is_published = models.BooleanField(default=True)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ('sort_order', 'name')

    def __str__(self):
        return f'{self.name} - {self.role}'


class ContactMessage(models.Model):
    name = models.CharField(max_length=120)
    email = models.EmailField()
    subject = models.CharField(max_length=200)
    message = models.TextField()
    is_read = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ('-created_at',)

    def __str__(self):
        return f'{self.subject} from {self.name}'


class SiteSettings(models.Model):
    notification_email = models.EmailField(default='cedarbells34@gmail.com')
    public_email = models.EmailField(default='cedarbells34@gmail.com')
    company_address = models.CharField(max_length=255, default='N8 Winners Estate, Enugu')
    map_url = models.URLField(default='https://www.google.com/maps/search/?api=1&query=N8+Winners+Estate+Enugu')
    map_embed_url = models.URLField(
        default='https://www.google.com/maps?q=N8+Winners+Estate+Enugu&output=embed'
    )
    facebook_url = models.URLField(blank=True)
    instagram_url = models.URLField(blank=True)
    linkedin_url = models.URLField(blank=True)
    twitter_url = models.URLField(blank=True)
    tiktok_url = models.URLField(blank=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = 'Site settings'
        verbose_name_plural = 'Site settings'

    def __str__(self):
        return 'Vaycancy site settings'

    @classmethod
    def current(cls):
        settings, _ = cls.objects.get_or_create(pk=1)
        return settings
