from rest_framework import serializers
from django.conf import settings

from home.models import Home, Tags, AboutMe, MyService, MyServiceTitle, MyResume, Education, Experience, Skill, \
    Knowledge, MainMenu


class TagSerializer(serializers.ModelSerializer):
    class Meta:
        model = Tags
        fields = ['tag', ]


class HomeSerializer(serializers.ModelSerializer):
    image = serializers.SerializerMethodField()
    tags = TagSerializer(read_only=True, many=True)

    class Meta:
        model = Home
        fields = ['name', 'title', 'button1', 'button2', 'keywords', 'tags', 'image', 'slug', 'created_at', 'video',
                  'updated_at', 'is_active']

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


class AboutMeSerializer(serializers.ModelSerializer):
    image = serializers.SerializerMethodField()

    class Meta:
        model = AboutMe
        fields = ['title', 'image', 'image_sub', 'cv', 'birthday', 'city', 'study', 'website', 'phone',
                  'age', 'interests', 'degree', 'x', 'mail', 'project_done', 'hapy_user', 'great_reviews', 'done',
                  'user_h', 'great', 'team', 'support_team', 'slug', 'created_at', 'updated_at', 'is_active',
                  'counter_active']

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


class MyServiceSerializer(serializers.ModelSerializer):
    image = serializers.SerializerMethodField()

    class Meta:
        model = MyService
        fields = ['title', 'image', 'content', 'slug', 'created_at', 'updated_at', 'is_active']

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


class MyServiceTitleSerializer(serializers.ModelSerializer):
    class Meta:
        model = MyServiceTitle
        fields = ['title', 'title_sub', 'created_at', 'updated_at', 'is_active']


class MainMenuSerializer(serializers.ModelSerializer):
    class Meta:
        model = MainMenu
        fields = '__all__'


class EducationSerializer(serializers.ModelSerializer):
    class Meta:
        model = Education
        fields = ['id', 'between_years', 'title', 'content', 'resume', 'created_at', 'updated_at', 'is_active']


class ExperienceSerializer(serializers.ModelSerializer):
    class Meta:
        model = Experience
        fields = ['id', 'between_years', 'title', 'content', 'resume', 'created_at', 'updated_at', 'is_active']


class SkillSerializer(serializers.ModelSerializer):
    class Meta:
        model = Skill
        fields = ['id', 'title', 'degree', 'resume', 'created_at', 'updated_at', 'is_active']


class KnowledgeSerializer(serializers.ModelSerializer):
    class Meta:
        model = Knowledge
        fields = ['id', 'title', 'resume', 'created_at', 'updated_at', 'is_active']


class MyResumeSerializer(serializers.ModelSerializer):
    edu_resume = EducationSerializer(many=True, read_only=True)
    exp_resume = ExperienceSerializer(many=True, read_only=True)
    skill_resume = SkillSerializer(many=True, read_only=True)
    know_resume = KnowledgeSerializer(many=True, read_only=True)

    class Meta:
        model = MyResume
        fields = ['id', 'title', 'title_sub', 'edu_resume', 'exp_resume', 'skill_resume', 'know_resume', 'created_at',
                  'updated_at', 'is_active', 'education', 'experience', 'coding_skills', 'knowledge']


"""
education
experience
coding_skills
knowledge
"""
