<?php

namespace App\Http\Requests\Item;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

	public function rules(): array
	{
		$current = $this->route('item');
		$currentId = $current ? $current->id : null;

		return [
			'name' => ['required', 'string', 'max:255'],
			'sku' => [
				'required', 'string', 'max:255',
				Rule::unique('accounts', 'sku')
					->ignore($currentId)
					->whereNull('deleted_at'), // Only check non-deleted items
			],
			'category_id' => ['required', 'integer', 'exists:chart_of_accounts,id'],
			'item_category_id' => ['nullable', 'integer', 'exists:chart_of_accounts,id'],
			// 'type' => ['required', 'string', 'in:RM,FG'],
			'uom_id' => ['nullable', 'integer', 'exists:uoms,id'],
			'unit_of_measure' => ['nullable', 'string', 'max:255'],
			// Barcode is auto-generated, so we don't validate it from user input
			// 'barcode' => [
			// 	'nullable', 'string', 'max:255',
			// 	Rule::unique('accounts', 'barcode')->ignore($currentId),
			// ],
			'price' => ['nullable', 'numeric', 'min:0'],
			'reorder_level' => ['nullable', 'numeric', 'min:0'],
			// 'status' => ['required', 'in:active,inactive'],
			// 'is_active' => ['sometimes', 'boolean'],
		];
	}
}
