<?php

namespace Modules\Admin\Http\Controllers;

use Illuminate\Routing\Controller;
use Modules\Admin\Services\BasketItemService;

class BasketItemController extends Controller
{
    public function __construct(
        private BasketItemService $basketItemService
    ) {}

    public function index()
    {
        $basketItems = $this->basketItemService->getAll();
        return view('admin::basket-items.index', compact('basketItems'));
    }

    public function show(int $id)
    {
        $basketItem = $this->basketItemService->findById($id);
        if (!$basketItem) {
            return redirect()->route('admin.basket-items.index')->with('error', 'Basket item not found.');
        }
        return view('admin::basket-items.show', compact('basketItem'));
    }

    public function destroy(int $id)
    {
        $this->basketItemService->delete($id);
        return redirect()->route('admin.basket-items.index')
            ->with('success', 'Basket item deleted successfully.');
    }
}
