<?php

namespace App\Http\Controllers\Admin\Manage\Restock;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Manage\RestockDraftItemRequest;
use App\Models\ProductVariant;
use App\Services\Manage\RestockService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class RestockDraftItemController extends Controller
{
    public function __construct(
        private readonly RestockService $restockService,
    ) {}

    public function store(RestockDraftItemRequest $request): JsonResponse
    {
        $item = $this->restockService->syncDraftItem($request->validated(), $request->user());

        return response()->json(['item' => $item]);
    }

    public function destroy(Request $request, ProductVariant $productVariant): JsonResponse
    {
        $this->restockService->removeDraftItem($request->user(), $productVariant);

        return response()->json(['ok' => true]);
    }
}
