from django.contrib.auth.models import User, Group
from rest_framework import serializers

from authentication.models import (
    UserProfile,
    Address,
    City,
    Province,
    SystemAddress,
    CityUnit
)


# سریالایزر مربوط به مدل استان
from panel.models import ManagementSendSms


class ProvinceSerializer(serializers.ModelSerializer):
    class Meta:
        model = Province
        fields = ['key', 'name']


# سریالایزر مربوط به مدل شهرستان
class CitySerializer(serializers.ModelSerializer):
    class Meta:
        model = City
        fields = ['key', 'name']


class CityForProductPricingSerializer(serializers.ModelSerializer):
    class Meta:
        model = City
        fields = ['key', 'name', 'product_price']


# سریالایزر مربوط به مدل زیر بخش شهرستان
class CityUnitSerializer(serializers.ModelSerializer):
    city = CitySerializer(read_only=True)

    class Meta:
        model = CityUnit
        fields = ['key', 'name']


# سریالایزر مربوط به مدل آدرس
class SystemAddressSerializer(serializers.ModelSerializer):
    province = ProvinceSerializer(required=False)
    city = CitySerializer(required=False)

    class Meta:
        model = SystemAddress
        fields = ['province', 'city', 'address', 'postal_code']


# سریالایزر مربوط به مدل آدرس
class AddressSerializer(serializers.ModelSerializer):
    class Meta:
        model = Address
        fields = '__all__'


# سریالایزر مربوط به مدل کاربر
class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'


# سریالایزر مربوط به مدل نقش
class GroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = ("name",)


# سریالایزر مربوط به مدل پروفایل کاربری
class UserProfileSerializer(serializers.ModelSerializer):
    address = AddressSerializer(read_only=True)

    class Meta:
        model = UserProfile
        fields = '__all__'


# سریالایزر مربوط به مدل شهرستان
class CityForLocSerializer(serializers.ModelSerializer):
    class Meta:
        model = City
        fields = ['name']


class SystemAddressForLocSerializer(serializers.ModelSerializer):
    city = CityForLocSerializer(required=False)

    class Meta:
        model = SystemAddress
        fields = ['city','address']


class ManagementSendSmsSerializer(serializers.ModelSerializer):
    class Meta:
        model = ManagementSendSms
        fields = '__all__'