from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers

from .models import SOURCES

MAX_DURATION = 120


class MusicSessionSerializer(serializers.Serializer):
    source = serializers.IntegerField()
    duration = serializers.IntegerField(min_value=0, max_value=MAX_DURATION)

    def validate_source(self, value):
        if value not in SOURCES:
            raise serializers.ValidationError(_(
                'You must choose an existing source'
            ))
        return value
