<?php

namespace Modules\Region\Controllers\Api;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Modules\Region\Models\Resources\RegionResource;
use Modules\Region\Services\RegionService;

class RegionController extends Controller
{

    public function __construct(
        private RegionService $regionService,
    ){}

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

    /**
     * Show the form for editing the specified Country.
     *
     * @param  int $id
     * @return JsonResponse
     */
    public function show(int $id) : JsonResponse
    {
        $region = $this->regionService->checkItem($id);
        if (!$region)
        {
            abort(404);
        }
        $region = $this->regionService->getItem($id);
        return ResponseService::response([
            'status'=>200,
            'message'=>'',
            'data'=>new RegionResource($region)
        ]);
    }


}
