"""Recipe app common serializers."""
from rest_framework import serializers
from recipe import models


class RecipeListSerializer(serializers.ModelSerializer):
    """Serializer for list of recipes."""

    title_translated = serializers.CharField(allow_null=True, read_only=True)
    subtitle_translated = serializers.CharField(allow_null=True, read_only=True)
    in_favorites = serializers.BooleanField()

    class Meta:
        """Meta class."""

        model = models.Recipe
        fields = (
            'id',
            'title_translated',
            'subtitle_translated',
            'author',
            'created_by',
            'published_at',
            'in_favorites',
        )
        read_only_fields = fields


class RecipeDetailSerializer(RecipeListSerializer):
    """Serializer for more information about the recipe."""

    description_translated = serializers.CharField(allow_null=True, read_only=True)

    class Meta(RecipeListSerializer.Meta):
        """Meta class."""

        fields = RecipeListSerializer.Meta.fields + ('description_translated',)
