from rest_framework import serializers

from core.models import GlobalSettings
from poizonstore.utils import PriceField


class GlobalSettingsSerializer(serializers.ModelSerializer):
    yuan_rate = PriceField(source='full_yuan_rate', read_only=True)
    yuan_rate_commission = PriceField()
    chinadelivery = PriceField(source='delivery_price_CN')
    commission = PriceField(source='commission_rub')
    pickup = serializers.CharField(source='pickup_address')

    class Meta:
        model = GlobalSettings
        fields = ('yuan_rate', 'yuan_rate_last_updated', 'yuan_rate_commission', 'commission',  'chinadelivery', 'pickup', 'time_to_buy')
        read_only_fields = ('yuan_rate_last_updated',)


class AnonymousGlobalSettingsSerializer(GlobalSettingsSerializer):
    class Meta:
        model = GlobalSettingsSerializer.Meta.model
        fields = tuple(set(GlobalSettingsSerializer.Meta.fields) - {'yuan_rate_commission', 'yuan_rate_last_updated'})
