from django.contrib.auth.models import AbstractUser
from django.db import models


class CustomUser(AbstractUser):
    vk_id = models.IntegerField(null=True, blank=True)
    yandex_id = models.BigIntegerField(null=True, blank=True)
    telegram_id = models.BigIntegerField(null=True, blank=True)
    telegram_username = models.TextField(null=True, blank=True)
    only_one_project = models.BooleanField(default=True)
    selected_project = models.ForeignKey('Project', on_delete=models.CASCADE, null=True)

    @property
    def profile_photo_url(self):
        return f"/profile_photo?id={self.id}"

    @property
    def projects(self):
        from web.models import Membership
        for membership in Membership.objects.filter(user=self):
            yield membership.project
