from django.db import models

from admin_panel.models import User, Business


class BusinessAccountant(models.Model):
    """Accountant created by a Business and scoped permanently to that Business."""

    business = models.ForeignKey(
        Business,
        on_delete=models.CASCADE,
        related_name="business_accountants",
    )
    user = models.OneToOneField(
        User,
        on_delete=models.CASCADE,
        related_name="business_accountant_profile",
    )
    created_by = models.ForeignKey(
        User,
        on_delete=models.PROTECT,
        related_name="business_accountants_created",
    )
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ["-created_at"]

    def __str__(self):
        return f"{self.user.username} - {self.business.name}"
