<?php

namespace Modules\Type\Controllers\Api;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Modules\Type\Models\Resources\TypeResource;
use Modules\Type\Services\TypeService;

class TypeController extends Controller
{

    public function __construct(
        private TypeService $typeService,
    ){}

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

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

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


}
