createdAt = new \DateTimeImmutable(); } // Getters public function getId(): ?int { return $this->id; } public function getTaskId(): int { return $this->taskId; } public function getAuthor(): string { return $this->author; } public function getAuthorType(): string { return $this->authorType; } public function getCommentType(): string { return $this->commentType; } public function getContent(): string { return $this->content; } public function getMetadata(): array { return $this->metadata; } public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; } // Setters public function setId(int $id): self { $this->id = $id; return $this; } public function setTaskId(int $taskId): self { $this->taskId = $taskId; return $this; } public function setAuthor(string $author): self { $this->author = $author; return $this; } public function setAuthorType(string $authorType): self { $this->authorType = $authorType; return $this; } public function setCommentType(string $commentType): self { $this->commentType = $commentType; return $this; } public function setContent(string $content): self { $this->content = $content; return $this; } public function setMetadata(array $metadata): self { $this->metadata = $metadata; return $this; } public function setCreatedAt(\DateTimeImmutable $createdAt): self { $this->createdAt = $createdAt; return $this; } public function toArray(): array { return [ 'id' => $this->id, 'task_id' => $this->taskId, 'author' => $this->author, 'author_type' => $this->authorType, 'comment_type' => $this->commentType, 'content' => $this->content, 'metadata' => $this->metadata, 'created_at' => $this->createdAt->format('Y-m-d H:i:s.u'), ]; } public static function fromArray(array $data): self { $comment = new self(); if (isset($data['id'])) { $comment->setId((int) $data['id']); } if (isset($data['task_id'])) { $comment->setTaskId((int) $data['task_id']); } if (isset($data['author'])) { $comment->setAuthor($data['author']); } if (isset($data['author_type'])) { $comment->setAuthorType($data['author_type']); } if (isset($data['comment_type'])) { $comment->setCommentType($data['comment_type']); } if (isset($data['content'])) { $comment->setContent($data['content']); } if (isset($data['metadata'])) { $metadata = is_string($data['metadata']) ? json_decode($data['metadata'], true) : $data['metadata']; $comment->setMetadata($metadata ?? []); } if (isset($data['created_at'])) { $comment->setCreatedAt(new \DateTimeImmutable($data['created_at'])); } return $comment; } public static function createStatusChange(int $taskId, string $author, string $authorType, string $oldStatus, string $newStatus): self { $comment = new self(); $comment->setTaskId($taskId); $comment->setAuthor($author); $comment->setAuthorType($authorType); $comment->setCommentType('status_change'); $comment->setContent("Status geändert: {$oldStatus} → {$newStatus}"); $comment->setMetadata(['old_status' => $oldStatus, 'new_status' => $newStatus]); return $comment; } public static function createAssignmentNote(int $taskId, string $author, string $authorType, string $assignee, string $assigneeType): self { $comment = new self(); $comment->setTaskId($taskId); $comment->setAuthor($author); $comment->setAuthorType($authorType); $comment->setCommentType('assignment'); $comment->setContent("Zugewiesen an {$assignee} ({$assigneeType})"); $comment->setMetadata(['assignee' => $assignee, 'assignee_type' => $assigneeType]); return $comment; } }