from django.db import models
from django.conf import settings
from core.models.Team import Team  # Adjust the import if Team is in a different app

class TeamMember(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='team_memberships', on_delete=models.CASCADE)
    team = models.ForeignKey(Team, related_name='members', on_delete=models.CASCADE , default=1)
    isAdmin = models.BooleanField(default=False)

    def __str__(self):
        return f"{self.user.username} in {self.team.name} - Admin: {self.isAdmin}"

    class Meta:
        unique_together = ('user', 'team')  # Ensure that a user is only added once per team
