# coding=utf-8

from rest_framework import serializers

from django.conf import settings

from apps.collection.models import Collection
from apps.base import Formater


class CollectionSerializer(serializers.ModelSerializer):
    name = serializers.CharField(source='commodity.name', read_only=True)
    image = serializers.SerializerMethodField()
    price = serializers.SerializerMethodField()
    vip_price = serializers.SerializerMethodField()
    point_price = serializers.CharField(source='commodity.point_price', read_only=True)
    price_type = serializers.CharField(source='commodity.type', read_only=True)

    class Meta:
        model = Collection
        fields = '__all__'

    def get_image(self, obj):
        if obj.commodity and obj.commodity.show_image:
            return obj.commodity.show_image.get_path()
        return ''

    def get_price(self, obj):
        return Formater.formatValueShow(obj.commodity.price)

    def get_vip_price(self, obj):
        return Formater.formatValueShow(obj.commodity.vip_price)
