from rest_framework import serializers
from reqman.apps.reqtool.models.requirements import BoilerplateGroupDictionary, Prefix, Boilerplate, BoilerplateData, BoilerplateGroup, InferenceResults, BoilerplateGroupClassesInstances


class BoilerplateSerializer(serializers.ModelSerializer):
    owner = serializers.ReadOnlyField(source='owner.username')
    class Meta:
        model = Boilerplate
        fields = ('id', 'group_of_boilerplate', 'owner', 'title', 'has_prefix', 'has_main', 'has_suffix')


class PrefixSerializer(serializers.ModelSerializer):
    #prefix_boilerplate = serializers.PrimaryKeyRelatedField(read_only=True)
    prefixgroup = serializers.PrimaryKeyRelatedField(read_only=True)
    class Meta:
        model = Prefix
        fields = '__all__'


class BoilerplateDataSerializer(serializers.ModelSerializer):
    owner_data = serializers.ReadOnlyField(source='owner.username')
    boilerplate_data_id = serializers.PrimaryKeyRelatedField(read_only=True)
    class Meta:
        model = BoilerplateData
        fields = '__all__'

class InferSerializer(serializers.ModelSerializer):
    owner_infer = serializers.ReadOnlyField(source='owner.username')
    #infer_group_of_boilerplate = serializers.PrimaryKeyRelatedField(read_only=True)
    class Meta:
        model = InferenceResults
        fields = '__all__'

class BoilerplateGroupSerializer(serializers.ModelSerializer):
    boilerplate_owner = serializers.ReadOnlyField(source='owner.username')
    class Meta:
        model = BoilerplateGroup
        fields = ('id', 'boilerplate_owner', 'ontology_file', 'title_bgroup', 'description')

class BoilerplateGroupClassesInstancesSerializer(serializers.ModelSerializer):
    classes_instances_owner = serializers.ReadOnlyField(source='owner.username')
    prefix_choices = serializers.JSONField()
    class Meta:
        model = BoilerplateGroupClassesInstances
        fields = '__all__'

class BoilerplateGroupDictionarySerializer(serializers.ModelSerializer):
    classes_instances_owner_dic = serializers.ReadOnlyField(source='owner.username')
    class Meta:
        model = BoilerplateGroupDictionary
        fields = '__all__'
