from django.db import models
from colorfield.fields import ColorField
from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFill

class Setting(models.Model):
    aktif = (
        (True, 'Evet'),
        (False, 'Hayır'),
    )
    title = models.CharField(max_length=254, verbose_name="Ayar Başlığı")
    meta_title = models.CharField(max_length=254, verbose_name="Meta Title", default='Meta Title')
    meta_description = models.CharField(max_length=254, verbose_name="Meta Description", default='Meta Description')
    phone = models.CharField(max_length=254, verbose_name="Telefon")
    url = models.CharField(max_length=254, verbose_name="Site İnternet Adresi", blank=True, null=True,
                           default='https://beyhanogur.com.tr')
    email = models.EmailField(max_length=254, verbose_name="E-Posta")
    facebook = models.CharField(max_length=254, verbose_name="Facebook", default='https://www.facebook.com', null=True,
                                blank=True)
    x = models.CharField(max_length=254, verbose_name="Twitter", default='https://www.twitter.com', null=True,
                               blank=True)
    instagram = models.CharField(max_length=254, verbose_name="Instagram", default='https://www.instagram.com',
                                 null=True, blank=True)
    whatsapp = models.CharField(max_length=254, verbose_name="Whatsapp", default='https://www.whatsapp.com', null=True,
                                blank=True)
    slogan = models.CharField(max_length=254, verbose_name="Başlık Solaganı", default='Dondurma', null=True, blank=True)
    w_logo = ProcessedImageField(upload_to='uploads/logo', null=True, blank=True, processors=[ResizeToFill(165, 54)],
                               format='PNG', options={'quality': 85})
    b_logo = ProcessedImageField(upload_to='uploads/logo', null=True, blank=True, processors=[ResizeToFill(165, 54)],
                               format='PNG', options={'quality': 85})
    created_at = models.DateTimeField(auto_now_add=True, editable=False, verbose_name="Oluşturulma Tarihi")
    updated_at = models.DateTimeField(auto_now=True, editable=False, verbose_name="Güncelleme Tarihi")
    is_active = models.BooleanField(default=False, verbose_name='Yayındamı', choices=aktif)


    class Meta:
        ordering = ["-created_at"]
        db_table = 'settings'
        verbose_name_plural = "Site Ayarları"
        verbose_name = "Site Ayarı"

    def __str__(self):
        return self.title


class Banner(models.Model):
    aktif = (
        (True, 'Evet'),
        (False, 'Hayır'),
    )
    color = ColorField(default='#FFFFFF', verbose_name='Yazı Rengi')
    title = models.CharField(max_length=254, verbose_name='Baner Adı', null=True)
    text1 = models.CharField(max_length=254, verbose_name='Baner Küçük Yazı 1', null=True)
    text2 = models.CharField(max_length=254, verbose_name='Baner Büyük Yazı 1', null=True)
    text4 = models.CharField(max_length=254, verbose_name='Baner Küçük Yazı 2', null=True)
    text5 = models.CharField(max_length=254, verbose_name='Baner Düğme Yazısı', null=True)
    image = ProcessedImageField(upload_to='uploads/banner/%Y',
                                processors=[ResizeToFill(1880, 950)],
                                format='JPEG',
                                options={'quality': 90})
    image_k = ProcessedImageField(upload_to='uploads/banner/kucuk/%Y',
                                  processors=[ResizeToFill(48, 48)],
                                  format='PNG',
                                  options={'quality': 90}, null=True, blank=True)
    image_k_txt = models.CharField(max_length=254, verbose_name='Küçük Resim Yazisi', null=True)
    is_active = models.BooleanField(default=True, verbose_name='Yayındamı ?', choices=aktif)

    created_at = models.DateTimeField(auto_now_add=True, editable=False, verbose_name="Oluşturulma Tarihi")
    updated_at = models.DateTimeField(auto_now=True, editable=False, verbose_name="Güncelleme Tarihi")

    class Meta:
        ordering = ["-created_at"]
        db_table = 'banners'
        verbose_name_plural = "Bannerler"
        verbose_name = "Banner"

    def __str__(self):
        return str(self.title)
