<?php

namespace App\Http\Controllers\Admin\Master\Product;

use App\Http\Controllers\Controller;
use App\Http\Requests\StockMutationRequest;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Services\StockMutationService;
use Inertia\Inertia;
use Inertia\Response;

class StockMutationController extends Controller
{
    public function __construct(
        private StockMutationService $service,
    ) {}

    public function index(StockMutationRequest $request, Product $product, ProductVariant $variant): Response
    {
        return Inertia::render('admin/master/product/variant/stock-mutations', [
            'product' => [
                'id' => $product->id,
                'name' => $product->name,
            ],
            'variant' => [
                'id' => $variant->id,
                'name' => $variant->name,
            ],
            'mutations' => $this->service->paginated($variant, ...$request->validatedWithDefaults()),
        ]);
    }
}
