<?php

namespace App\Http\Controllers\api\v1;

use App\Traits\JsonResponseTrait;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests\Blog\AddBlogRequest;
use App\Http\Requests\Blog\GetBlogsRequest;
use App\Http\Requests\Blog\GetBlogCategoriesRequest;
use App\Http\Requests\Blog\GetBlogRequest;
use App\Http\Requests\Blog\UpdateReadCountRequest;
use App\Service\BlogService;

class BlogController extends Controller
{
    use JsonResponseTrait;
    protected $blogService;

    /**
     * Inject the BlogService dependency.
     */
    public function __construct(BlogService $blogService)
    {
        $this->blogService = $blogService;
    }

    public function getBlogs(GetBlogsRequest $request)
    {
        $filters = $request->validated();
        return $this->blogService->getBlogs($filters);
    }

    public function getBlogById($blogId)
    {
        return $this->blogService->getBlogById($blogId);
    }

    public function updateReadCount($blogId)
    {
        $result = $this->blogService->updateReadCount($blogId);

        return $result;
    }

    public function getBlogCategories(GetBlogCategoriesRequest $request)
    {
        $filters = $request->validated();
        return $this->blogService->getBlogCategories($filters);
    }

    public function getBlogCategoryById($categoryId)
    {
        return $this->blogService->getBlogCategoryById($categoryId);
    }
}
