<?php

namespace App\Services;

class NotificationService
{
    private \App\Models\Notification $model;

    public function __construct()
    {
        $this->model = new \App\Models\Notification();
    }

    public function notifyNewComment(int $postOwnerId, int $commenterId, string $postTitle, string $postSlug): void
    {
        if ($postOwnerId === $commenterId) return;
        $this->model->create($postOwnerId, 'new_comment', [
            'content' => "New comment on your post: $postTitle",
            'url' => "/post/$postSlug"
        ]);
    }

    public function notifyVote(int $ownerId, int $voterId, string $type): void
    {
        if ($ownerId === $voterId) return;
        $this->model->create($ownerId, 'vote', [
            'content' => "Someone voted on your $type",
        ]);
    }

    public function notifyBestAnswer(int $userId, string $postTitle, string $postSlug): void
    {
        $this->model->create($userId, 'best_answer', [
            'content' => "Your answer was accepted as best in: $postTitle",
            'url' => "/post/$postSlug"
        ]);
    }
}
