<?php

namespace Modules\Reason\Controllers\Api;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Modules\Reason\Models\Resources\ReasonResource;
use Modules\Reason\Services\ReasonService;

class ReasonController extends Controller
{

    public function __construct(
        private ReasonService $reasonService,
    ){}

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

    /**
     * Show the form for editing the specified Reason.
     *
     * @param  int $id
     * @return JsonResponse
     */
    public function show(int $id) : JsonResponse
    {
        $reason = $this->reasonService->checkItem($id);
        if (!$reason)
        {
            abort(404);
        }
        $reason = $this->reasonService->getItem($id);

        return ResponseService::response([
            'status'=>200,
            'message'=>'',
            'data'=>new ReasonResource($reason)
        ]);
    }


}
