<?php

namespace Modules\Option\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\Option\Enums\OptionStatusEnum;
use Modules\Option\Models\Option;
use Modules\Option\Models\Resources\OptionResource;
use Modules\Option\Services\OptionService;

class OptionController extends Controller
{
    
    private OptionService $optionService;

    public function __construct(OptionService $optionService)
    {
        $this->optionService = $optionService;
    }


    /**
     * Display a listing of the faqs.
     *
     * @param Request $request
     * @return View
     */
    public function subjects(Request $request) :JsonResponse
    {
        $request->merge(['type'=>OptionStatusEnum::SUBJECT->value]);
        $options = $this->optionService->get($request);
        $options = OptionResource::collection($options);
        $response = [
            'status'=>200,
            'message'=>'',
            'data'=> $options
        ];
        return ResponseService::response($response);
    }
    
    public function reasons(Request $request) :JsonResponse
    {
        $request->merge(['type'=>OptionStatusEnum::COMPLAINT->value]);
        $options = $this->optionService->get($request);
        $options = OptionResource::collection($options);
        $response = [
            'status'=>200,
            'message'=>'',
            'data'=> $options
        ];
        return ResponseService::response($response);
    }
}
