# coding=utf-8

from rest_framework import serializers

from apps.base import Formater
from apps.rebate.models import PointLog, CashLog


class PointLogSerializer(serializers.ModelSerializer):
    type_text = serializers.CharField(source='get_type_display', read_only=True)
    happen_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)

    class Meta:
        model = PointLog
        fields = ('type_text', 'happen_time', 'amount', 'balance', )


class CashLogSerializer(serializers.ModelSerializer):
    type_text = serializers.CharField(source='get_type_display', read_only=True)
    happen_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)
    amount = serializers.SerializerMethodField()
    balance = serializers.SerializerMethodField()

    class Meta:
        model = CashLog
        fields = ('type_text', 'happen_time', 'amount', 'balance', )

    def get_amount(self, obj):
        return Formater.formatValueShow(obj.amount)

    def get_balance(self, obj):
        return Formater.formatValueShow(obj.balance)
