<?php

namespace App\Modules\Procurement\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Procurement\Requests\BulkValidateGoodsReceiptsRequest;
use App\Modules\Procurement\Services\GoodsReceiptBulkValidateService;
use Illuminate\Http\RedirectResponse;

class GoodsReceiptBulkOperationsController extends Controller
{
    public function validateReceipts(
        BulkValidateGoodsReceiptsRequest $request,
        GoodsReceiptBulkValidateService $service,
    ): RedirectResponse {
        $user = $request->user();
        $tenantId = (int) $user->tenant_id;
        abort_if($tenantId === 0, 403);
        $result = $service->run($user, $tenantId, $request->validated('ids'));

        return back()->with('bulk_result', $result->toSessionPayload());
    }
}
