<?php

namespace Modules\Faq\Controllers\Api;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Exception;
use Illuminate\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Http\RedirectResponse;
use App\Http\Controllers\Controller;
use Modules\Faq\Enums\FaqStatusEnum;
use Modules\Faq\Models\Faq;
use Modules\Faq\Models\Resources\FaqResource;
use Modules\Faq\Services\FaqService;

class FaqController extends Controller
{
    
    private FaqService $faqService;

    public function __construct(FaqService $faqService)
    {
        $this->faqService = $faqService;
    }

    /**
     * Display a listing of the faqs.
     *
     * @param Request $request
     * @return View
     */
    public function users(Request $request) :JsonResponse
    {
        $request->merge(['statusType'=>FaqStatusEnum::User->value]);
        $faqs = $this->faqService->get($request);
        $faqs = FaqResource::collection($faqs);
        $response = [
            'status'=>200,
            'message'=>'',
            'data'=> $faqs
        ];
        return ResponseService::response($response);
    }

    public function stores(Request $request) :JsonResponse
    {
        $request->merge(['statusType'=>FaqStatusEnum::Store->value]);
        $faqs = $this->faqService->get($request);
        $faqs = FaqResource::collection($faqs);
        $response = [
            'status'=>200,
            'message'=>'',
            'data'=> $faqs
        ];
        return ResponseService::response($response);
    }
}
