from rest_framework import serializers
from core.models.TeamMember import TeamMember

class TeamMemberSerializer(serializers.ModelSerializer):
    class Meta:
        model = TeamMember
        fields = ['user', 'adminUser', 'isAdmin']
        read_only_fields = ['adminUser']

    def create(self, validated_data):
        """
        Override the create method to automatically assign the admin user (request.user).
        """
        admin_user = validated_data.pop('adminUser', None)
        team_member = TeamMember.objects.create(adminUser=self.context['request'].user, **validated_data)
        return team_member
