# from rest_framework import serializers
# from .models import liuyao

# class LiuyaoSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = liuyao
#         fields = '__all__'

# from datetime import datetime
# from django.core.validators import RegexValidator

# class LiuyaoCalculatorSerializer(serializers.ModelSerializer):
#     usecur = serializers.BooleanField(required=False, default=False)
#     year = serializers.IntegerField(max_value=9999, min_value=1000, required=False)
#     month = serializers.IntegerField(max_value=12, min_value=1, required=False)
#     day = serializers.IntegerField(max_value=31, min_value=1, required=False)
#     time = serializers.CharField(
#         max_length=5,
#         required=False,
#         validators=[
#             RegexValidator(
#                 regex=r"^\d{2}:\d{2}$",
#                 message="Invalid time format. Use 'HH:MM'."
#             )
#         ]
#     )

#     class Meta:
#         model = liuyao
#         fields = ['y1', 'y2', 'y3', 'y4', 'y5', 'y6', 'question', 'usecur', 'year', 'month', 'day', 'time']

#     def validate(self, attrs):
#         usecur = attrs.get('usecur', False)
#         year = attrs.get('year')
#         month = attrs.get('month')
#         day = attrs.get('day')
#         time = attrs.get('time', "00:00")

#         # Validate date
#         if not usecur and (year is not None and month is not None and day is not None):
#             try:
#                 datetime(year, month, day)  # Validate if date is valid
#             except ValueError:
#                 raise serializers.ValidationError({
#                     'year': f"Invalid date ({year}-{month:02d}-{day:02d}).",
#                     'month': f"Invalid date ({year}-{month:02d}-{day:02d}).",
#                     'day': f"Invalid date ({year}-{month:02d}-{day:02d}).",
#                 })

#         # Validate time format
#         try:
#             hours, minutes = map(int, time.split(':'))
#             if not (0 <= hours <= 23 and 0 <= minutes <= 59):
#                 raise ValueError
#         except ValueError:
#             raise serializers.ValidationError({
#                 'time': "Invalid time format. Use 'HH:MM'."
#             })

#         return attrs
