<?php

namespace Modules\FaqCategory\Controllers\Api;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Modules\FaqCategory\Models\Resources\FaqCategoryResource;
use Modules\FaqCategory\Services\FaqCategoryService;

class FaqCategoryController extends Controller
{

    public function __construct(
        private FaqCategoryService $categoryService,
    ){}

    /**
     * Display a listing of the countries.
     *
     * @param Request $request
     * @return JsonResponse
     */
    public function index(Request $request):JsonResponse
    {
        $cities = $this->categoryService->get();
        return ResponseService::response([
            'status'=>200,
            'message'=>'',
            'data'=>FaqCategoryResource::collection($cities)
        ]);
    }

    /**
     * Show the form for editing the specified Country.
     *
     * @param  int $id
     * @return JsonResponse
     */
    public function show(int $id) : JsonResponse
    {
        $category = $this->categoryService->checkItem($id);
        if (!$category)
        {
            abort(404);
        }
        $category = $this->categoryService->getItem($id);
        return ResponseService::response([
            'status'=>200,
            'message'=>'',
            'data'=>new FaqCategoryResource($category)
        ]);
    }


}
