from datetime import UTC, datetime
from typing import NewType, Self
from uuid import UUID

from uuid_utils.compat import uuid7

from template_project.application.common.entity import Entity, to_entity
from template_project.application.user.entity import UserId

ProfileId = NewType("ProfileId", UUID)


@to_entity
class Profile(Entity[ProfileId]):
    user_id: UserId
    email: str | None
    display_name: str | None
    first_name: str | None
    last_name: str | None
    avatar_url: str | None
    phone: str | None

    @classmethod
    def factory(
        cls,
        user_id: UserId,
        email: str | None = None,
        display_name: str | None = None,
        first_name: str | None = None,
        last_name: str | None = None,
        avatar_url: str | None = None,
        phone: str | None = None,
    ) -> Self:
        return cls(
            id=ProfileId(uuid7()),
            user_id=user_id,
            email=email,
            display_name=display_name,
            first_name=first_name,
            last_name=last_name,
            avatar_url=avatar_url,
            phone=phone,
            created_at=datetime.now(tz=UTC),
        )
