<?php

namespace App\Http\Requests;

use App\Models\InventoryTransferDocument;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class QuickInventoryTransferRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('create', InventoryTransferDocument::class);
    }

    public function rules(): array
    {
        return [
            'transfer_type' => ['required', 'string', Rule::in([
                InventoryTransferDocument::TRANSFER_INBOUND_RECEIPT,
                InventoryTransferDocument::TRANSFER_OUTBOUND,
            ])],
            'notes' => ['nullable', 'string', 'max:2000'],
            'lines' => ['required', 'array', 'min:1'],
            'lines.*.inventory_product_id' => [
                'required',
                'integer',
                Rule::exists('inventory_products', 'id')->where('active', true),
            ],
            'lines.*.quantity' => ['required', 'numeric', 'min:0.0001'],
            'lines.*.sort_order' => ['sometimes', 'integer', 'min:0'],
        ];
    }
}
