<?php

declare(strict_types=1);

namespace App\Http\Controllers\Post;

use App\Http\Controllers\Controller;
use App\Models\Post;
use App\Support\ApiResponse;
use Illuminate\Http\Request;

class PostIncreaseViewController extends Controller
{
    /**
     * Handle the incoming request.
     */
    public function __invoke(Request $request, Post $post)
    {
        $post->increment('views');
        $post->refresh();

        return ApiResponse::success($post->view_count);
    }
}
