"""Value object for comment content. This module defines the CommentContent value object that validates and encapsulates comment text content. """ from dataclasses import dataclass from app.domain.value_objects.base import ValueObject @dataclass(frozen=True, slots=True) class CommentContent(ValueObject[str]): """Comment content value object. Wraps and validates comment content ensuring it meets length requirements and is not empty. Attributes: value: The comment content string. MAX_LENGTH: Maximum allowed content length (5000 characters). Raises: ValueError: If content is empty or too long. Example: >>> content = CommentContent("This is a **bold** comment.") >>> content.value 'This is a **bold** comment.' """ MAX_LENGTH: int = 5000 def _validate(self) -> None: """Validate comment content. Checks that content is a non-empty string within length bounds. Raises: ValueError: If content fails validation criteria. """ if not isinstance(self.value, str): raise ValueError("Comment content must be a string") if not self.value.strip(): raise ValueError("Comment content cannot be empty") if len(self.value) > self.MAX_LENGTH: raise ValueError(f"Comment content must be at most {self.MAX_LENGTH} characters")