"""标签领域实体。"""

from dataclasses import dataclass, field
from datetime import datetime, timezone
from uuid import uuid4


@dataclass(slots=True)
class Tag:
    id: str
    user_id: str
    name: str
    created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))

    @classmethod
    def create(cls, user_id: str, name: str) -> "Tag":
        clean_name = name.strip()
        if not clean_name:
            raise ValueError("标签名称不能为空")
        return cls(
            id=uuid4().hex,
            user_id=user_id,
            name=clean_name,
        )
