<?php

namespace Modules\Admin\Http\Controllers;

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

class CartItemController extends Controller
{
    public function __construct(
        private CartItemService $cartItemService
    ) {}

    public function index()
    {
        $cartItems = $this->cartItemService->getAll();
        return view('admin::cart-items.index', compact('cartItems'));
    }

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

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