<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Resources\WhyBestResource;
use Exception;
use App\Services\WhyBestService;
use App\Http\Controllers\Controller;
use App\Http\Requests\PaginateRequest;

class WhyBestController extends Controller
{
    private WhyBestService $whyBestService;

    public function __construct(WhyBestService $whyBestService)
    {
        $this->whyBestService = $whyBestService;
    }

    public function index(PaginateRequest $request): \Illuminate\Http\Response | \Illuminate\Http\Resources\Json\AnonymousResourceCollection | \Illuminate\Contracts\Foundation\Application | \Illuminate\Contracts\Routing\ResponseFactory
    {
        try {
            return WhyBestResource::collection($this->whyBestService->list($request));
        } catch (Exception $exception) {
            return response(['status' => false, 'message' => $exception->getMessage()], 422);
        }
    }
}