<?php

namespace Modules\PaymentWay\Controllers\Api;

/** Ajax Request */

use App\Services\Response\ResponseService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use Modules\PaymentWay\Models\Resources\PaymentWayResource;
use Modules\PaymentWay\Services\PaymentWayService;

class PaymentWayController extends Controller
{

    public function __construct(
        private PaymentWayService $paymentWayService,
    ){}

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

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

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


}
