<?php

namespace App\Services;

use App\Models\Comment;
use App\Models\Reply;
use App\Models\User;
use Illuminate\Pagination\LengthAwarePaginator;

class ReplyService
{
    public function forComment(Comment $comment, int $perPage = 10): LengthAwarePaginator
    {
        return $comment->replies()
            ->with(['user', 'likes'])
            ->withCount('likes')
            ->latest()
            ->paginate($perPage);
    }

    public function create(User $user, Comment $comment, string $content): Reply
    {
        return Reply::create([
            'comment_id' => $comment->id,
            'user_id'    => $user->id,
            'content'    => $content,
        ]);
    }

    public function update(Reply $reply, string $content): Reply
    {
        $reply->update(['content' => $content]);
        return $reply;
    }

    public function delete(Reply $reply): void
    {
        $reply->delete();
    }
}
