<?php

namespace Modules\City\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Modules\City\Models\City;
use Modules\City\Resources\Api\CityResource;
use Modules\City\Services\CityService;


class CityController extends Controller
{

    public function __construct(
        private CityService $cityService,
    ) {
    }

    /**
     * Get Cities.
     * @param Request $request
     * @return JsonResponse
     */
    public function index(Request $request): void
    {
        $credentials['api'] = true;
        $query = $this->cityService->get($credentials);

        $response = [
            "query" => $query,
            "request" => $request,
            "resourceClass" => CityResource::class,
            "returnName" => "cities"
        ];
        ResponseService::fetchPainateDate($response);
    }
    /**
     * Get City.
     *
     * @param Request $request
     * @param City $city
     * @return JsonResponse
     */
    public function show(Request $request, City $city): JsonResponse
    {
        $chip = $this->cityService->getItem($city->id);

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

}
