<?php

namespace Modules\Setting\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;


use Modules\Faq\Services\FaqService;
use Modules\Page\Services\PageService;
use Modules\Setting\Resources\Api\FaqResource;
use Modules\Setting\Resources\Api\PageResource;
use Modules\Setting\Resources\Api\SettingResource;
use Modules\Setting\Services\SettingService;
class SettingController extends Controller
{

    public function __construct(
        private SettingService $settingService,
        private FaqService $faqService,
        private PageService $pageService,
    ) {
    }
    /**
     * Get Main Settings.
     *
     * @param Request $request
     * @return JsonResponse
     */
    public function index(Request $request): JsonResponse
    {
        $data = $this->settingService->get($request);
        $response = [
            'status' => 200,
            'message' => '',
            'data' => new SettingResource($data)
        ];
        return ResponseService::response($response);
    }
    /**
     * Get Faqs .
     *
     * @param Request $request
     * @return JsonResponse
     */
    public function faqs(Request $request): void
    {
        $credentials['type'] = auth()->check() && auth()->user()->role == 6 ? 1 : 0;
        $credentials['api'] = true;
        $query = $this->faqService->get($credentials);

        $response = [
            "query" => $query,
            "request" => $request,
            "resourceClass" => FaqResource::class,
            "returnName" => "faqs"
        ];
        ResponseService::fetchPainateDate($response);
    }
    /**
     * Get Pages .
     *
     * @param Request $request
     * @return JsonResponse
     */
    public function pages(Request $request): JsonResponse
    {
        $data = $this->pageService->get($request);
        $response = [
            'status' => 200,
            'message' => '',
            'data' => PageResource::collection($data)
        ];
        return ResponseService::response($response);
    }


}
