from rest_framework import serializers
from api.account.serializers.alert_serializers import AlertSerializer

class ChartDataSerializer(serializers.Serializer):
    timestamp = serializers.DateTimeField()
    value = serializers.IntegerField()

class DashboardSerializer(serializers.Serializer):
    chart_data = ChartDataSerializer(many=True, required=False)
    table_data = AlertSerializer(many=True, read_only=True)

    def to_representation(self, instance):
        return {
            'chart_data': instance['chart_data'],
            'table_data': AlertSerializer(instance['table_data'], many=True).data
        }

    class Meta:
        fields = ('chart_data', 'table_data')