from rest_framework import serializers

from api.models import Hero, Item


class HeroSerializer(serializers.ModelSerializer):
    primary = serializers.SerializerMethodField()

    class Meta:
        model = Hero
        fields = ["id", "name", "primary"]

    def get_primary(self, obj):
        return obj.primary.lower()


class ItemSerializer(serializers.ModelSerializer):
    class Meta:
        model = Item
        fields = ["id", "name"]


class RandomizeBuildRequestSerializer(serializers.Serializer):
    includeSkills = serializers.BooleanField()
    includeAspect = serializers.BooleanField()
    itemsCount = serializers.IntegerField(min_value=1)
    heroId = serializers.IntegerField(required=False, allow_null=True)


class RandomizeBuildResponseSerializer(serializers.Serializer):
    hero = HeroSerializer()
    items = ItemSerializer(many=True)
    skillBuild = serializers.DictField(
        child=serializers.CharField(),
        required=False,
        help_text="Map of level (1-25) to skill (q/w/e/r/left_talent/right_talent)"
    )
    aspect = serializers.CharField(required=False)
