# coding=utf-8

from rest_framework import serializers
from apps.WechatApplet.models import WechatApplet, MessageTemplate


class WechatAppletSerializer(serializers.ModelSerializer):
    audit_status_text = serializers.CharField(source='get_audit_status_display', read_only=True)
    agent_name = serializers.CharField(source='agent.name', read_only=True)
    authorize_text = serializers.SerializerMethodField()

    def get_authorize_text(self, obj):
        if obj.is_authorize:
            return u'是'
        return u'否'

    class Meta:
        model = WechatApplet
        fields = '__all__'


class MsgTemplateSerializer(serializers.ModelSerializer):
    type_text = serializers.CharField(source='get_type_display', read_only=True)
    nick_name = serializers.CharField(source='wechat_app.nick_name', read_only=True)
    principal_name = serializers.CharField(source='wechat_app.principal_name', read_only=True)
    agent_name = serializers.CharField(source='wechat_app.agent.name', read_only=True)

    class Meta:
        model = MessageTemplate
        fields = '__all__'
