<?php

namespace App\Http\Controllers\api\v1\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Blog\CreateBlogRequest;
use App\Http\Requests\Admin\Blog\UpdateBlogRequest;
use App\Service\Admin\BlogService;
use App\Traits\JsonResponseTrait;
use Illuminate\Http\Request;

class BlogController extends Controller
{
    use JsonResponseTrait;

    public function __construct(protected BlogService $blogService) {}

    /**
     * Get all blogs
     */
    public function index()
    {
        return $this->blogService->getAllBlogs();
    }

    /**
     * Get blog by ID
     */
    public function show(string $blog_id)
    {
        return $this->blogService->getBlogById($blog_id);
    }

    /**
     * Create new blog
     */
    public function store(CreateBlogRequest $request)
    {
        $input = $request->validated();
        $authUser = $request->user(); // Get authenticated user
        return $this->blogService->createBlog($input, $authUser);
    }

    /**
     * Update blog
     */
    public function update(UpdateBlogRequest $request, string $blog_id)
    {
        $input = $request->validated();
        $authUser = $request->user(); // Get authenticated user
        return $this->blogService->updateBlog($blog_id, $input, $authUser);
    }

    /**
     * Delete blog
     */
    public function destroy(string $blog_id)
    {
        return $this->blogService->deleteBlog($blog_id);
    }

    /**
     * Toggle blog status
     */
    public function toggleStatus(string $blog_id)
    {
        return $this->blogService->toggleBlogStatus($blog_id);
    }
}
