<?php

namespace Modules\Offer\Controllers\Api;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Modules\Offer\Models\Resources\OfferResource;
use Modules\Offer\Services\OfferService;

class OfferController extends Controller
{

    public function __construct(
        private OfferService $offerService,
    ){}

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

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

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


}
