<?php

namespace App\Http\Requests\PurchaseRequest;

use Illuminate\Foundation\Http\FormRequest;

class StorePurchaseRequestRequest extends FormRequest
{
	public function authorize(): bool
	{
		return true;
	}

	public function rules(): array
	{
		return [
			'pr_number' => ['required', 'string', 'max:255', 'unique:purchase_requests,pr_number'],
			'title' => ['nullable', 'string', 'max:255'],
			'description' => ['nullable', 'string'],
			'expected_date' => ['required', 'date'],
			// 'required_date' => ['nullable', 'date'],
			'priority' => ['nullable', 'string', 'in:low,medium,high,urgent'],
			'unit_code' => ['nullable', 'string', 'max:50'],
			'remarks' => ['nullable', 'string'],
			'items' => ['required', 'array', 'min:1'],
			'items.*.item_id' => ['required', 'integer', 'exists:accounts,id', 'distinct'],
			'items.*.item_variation_id' => ['nullable', 'integer', 'exists:item_variations,id'],
			'items.*.quantity' => ['required', 'numeric', 'min:0.000001'],
			'items.*.unit_code' => ['nullable', 'string', 'max:50'],
		];
	}
}
