from rest_framework import serializers

from user.serializers import UserSerializer
from . import models


class SettingSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Setting
        fields = '__all__'
        extra_kwargs = {
            'pre_booking_interval_day': {
                'min_value': 1
            },
            'punish_point': {
                'min_value': 1
            },
            'reward_point': {
                'min_value': 1
            },
        }

    # TODO
    def validate_booking_interval(self, value):
        if (not value in [30, 60]):
            raise serializers.ValidationError('请确保该值等于30或者60。')
        return value


class RoomSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Room
        fields = '__all__'


class SeatSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Seat
        fields = '__all__'


class BookingSerializer(serializers.ModelSerializer):
    user = UserSerializer()
    room = RoomSerializer()
    seats = SeatSerializer(many=True)
    cancel_by = UserSerializer()

    class Meta:
        model = models.Booking
        fields = '__all__'


class BookingCreateSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Booking
        fields = '__all__'


class BookingCancelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Booking
        fields = ['cancel_reason']
