from rest_framework import serializers
from django.conf import settings

# from product.models import Category, Product, Images, Tags
from settings.models import Setting, SiteSettings, Banner

class SettingSerializer(serializers.ModelSerializer):
    b_logo = serializers.SerializerMethodField()
    w_logo = serializers.SerializerMethodField()

    class Meta:
        model = Setting
        fields = ['title', 'meta_title', 'meta_description', 'phone', 'url', 'email', 'facebook', 'x','pinterest','linkedin',
                  'instagram', 'whatsapp', 'slogan', 'w_logo', 'b_logo', 'created_at',
                  'updated_at', 'is_active']

    def get_w_logo(self, obj):
        if obj.w_logo:
            # Sadece path döndür, domain olmadan
            return obj.w_logo.url
        return None

    def get_b_logo(self, obj):
        if obj.b_logo:
            # Sadece path döndür, domain olmadan
            return obj.b_logo.url
        return None


class SettingOpenCloseSerializer(serializers.ModelSerializer):

    class Meta:
        model = SiteSettings
        fields = ['is_active','site_active']


class BannerSerializer(serializers.ModelSerializer):
    images = serializers.SerializerMethodField()
    sub_images = serializers.SerializerMethodField()

    class Meta:
        model = Banner
        fields = ['id', 'color', 'title', 'sub_text', 'button_text', 'images', 'sub_images', 'is_active', 'created_at', 'updated_at']

    def get_images(self, obj):
        if obj.images:
            return obj.images.url
        return None

    def get_sub_images(self, obj):
        if obj.sub_images:
            return obj.sub_images.url
        return None
