<?php

namespace Modules\Chip\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Modules\Chip\Models\Chip;
use Modules\Chip\Resources\Api\ChipResource;
use Modules\Chip\Services\ChipService;


class ChipController extends Controller
{

    public function __construct(
        private ChipService $chipService,
    ) {
    }

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

        $response = [
            "query" => $query,
            "request" => $request,
            "resourceClass" => ChipResource::class,
            "returnName" => "chips"
        ];
        ResponseService::fetchPainateDate($response);
    }
    /**
     * Get Chip.
     *
     * @param Request $request
     * @param Chip $product
     * @return JsonResponse
     */
    public function show(Request $request, Chip $chip): JsonResponse
    {
        $chip = $this->chipService->getItem($chip->id);

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

}
