<?php

namespace Modules\Brand\Controllers\Api;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Modules\Brand\Models\Resources\BrandResource;
use Modules\Brand\Services\BrandService;

class BrandController extends Controller
{

    public function __construct(
        private BrandService $brandService,
    ){}

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

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


}
