from rest_framework import serializers

from .. import models
from .sound import SoundSerializer
from .admin import TrackSerializer


class EpisodeSoundSerializer(serializers.ModelSerializer):
    sound = SoundSerializer(read_only=True)

    class Meta:
        model = models.EpisodeSound
        fields = [
            "id",
            "position",
            "episode",
            "broadcast",
            "sound",
            "sound_id",
        ]


class EpisodeSerializer(serializers.ModelSerializer):
    playlist = EpisodeSoundSerializer(source="episodesound_set", many=True, read_only=True)
    tracks = TrackSerializer(source="track_set", many=True, read_only=True)

    class Meta:
        model = models.Episode
        fields = [
            "id",
            "title",
            "content",
            "pub_date",
            "playlist",
            "tracks",
        ]
