<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreLoanRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'borrower_name' => ['required', 'string', 'max:255'],
            'borrower_phone' => ['nullable', 'string', 'max:50'],
            'borrower_unit' => ['nullable', 'string', 'max:255'],
            'loaned_at' => ['required', 'date'],
            'due_at' => ['nullable', 'date', 'after_or_equal:loaned_at'],
            'notes' => ['nullable', 'string'],
            'lines' => ['required', 'array', 'min:1'],
            'lines.*.item_id' => ['nullable', 'exists:items,id'],
            'lines.*.asset_unit_id' => ['nullable', 'exists:asset_units,id'],
            'lines.*.quantity' => ['required', 'integer', 'min:1'],
            'lines.*.condition_on_loan' => ['nullable', 'in:good,minor,major'],
            'lines.*.notes' => ['nullable', 'string'],
        ];
    }
}
