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

class CustomUser(AbstractUser):
    # Email koristimo za login, pa mora biti jedinstven
    email = models.EmailField(unique=True)
    
    # Dodatna polja za tvoju tvrtku
    telefon = models.CharField(max_length=20, blank=True)
    oib = models.CharField(max_length=11, blank=True, null=True)
    is_serviser = models.BooleanField(default=False) # Razlikovanje uloga

    # Govorimo Djangu da koristi email umjesto username-a
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username', 'first_name', 'last_name']

    def __str__(self):
        return f"{self.first_name} {self.last_name} ({self.email})"