<?php

namespace App\Http\Requests\ItemVariation;

use Illuminate\Foundation\Http\FormRequest;

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

	public function rules(): array
	{
		return [
			'item_id' => ['required', 'integer', 'exists:accounts,id'],
			'name' => ['required', 'string', 'max:255'],
			'sku_suffix' => ['nullable', 'string', 'max:255'],
			'size' => ['nullable', 'string', 'max:100'],
			'color' => ['nullable', 'string', 'max:100'],
			'unit' => ['nullable', 'string', 'max:50'],
			'length' => ['nullable', 'numeric', 'min:0', 'max:999999.99'],
			'width' => ['nullable', 'numeric', 'min:0', 'max:999999.99'],
			'height' => ['nullable', 'numeric', 'min:0', 'max:999999.99'],
			'weight' => ['nullable', 'numeric', 'min:0', 'max:999999.99'],
			'weight_unit' => ['nullable', 'string', 'in:kg,g,lb,oz'],
			'cost_price' => ['nullable', 'numeric', 'min:0', 'max:999999.9999'],
			'selling_price' => ['nullable', 'numeric', 'min:0', 'max:999999.9999'],
			'is_active' => ['boolean'],
			'description' => ['nullable', 'string', 'max:1000'],
		];
	}

	public function messages(): array
	{
		return [
			'item_id.required' => 'Item is required.',
			'item_id.exists' => 'Selected item does not exist.',
			'name.required' => 'Variation name is required.',
			'name.max' => 'Variation name cannot exceed 255 characters.',
			'sku_suffix.max' => 'SKU suffix cannot exceed 255 characters.',
			'size.max' => 'Size cannot exceed 100 characters.',
			'color.max' => 'Color cannot exceed 100 characters.',
			'unit.max' => 'Unit cannot exceed 50 characters.',
			'length.numeric' => 'Length must be a valid number.',
			'length.min' => 'Length cannot be negative.',
			'length.max' => 'Length cannot exceed 999,999.99.',
			'width.numeric' => 'Width must be a valid number.',
			'width.min' => 'Width cannot be negative.',
			'width.max' => 'Width cannot exceed 999,999.99.',
			'height.numeric' => 'Height must be a valid number.',
			'height.min' => 'Height cannot be negative.',
			'height.max' => 'Height cannot exceed 999,999.99.',
			'weight.numeric' => 'Weight must be a valid number.',
			'weight.min' => 'Weight cannot be negative.',
			'weight.max' => 'Weight cannot exceed 999,999.99.',
			'weight_unit.in' => 'Weight unit must be kg, g, lb, or oz.',
			'cost_price.numeric' => 'Cost price must be a valid number.',
			'cost_price.min' => 'Cost price cannot be negative.',
			'cost_price.max' => 'Cost price cannot exceed 999,999.9999.',
			'selling_price.numeric' => 'Selling price must be a valid number.',
			'selling_price.min' => 'Selling price cannot be negative.',
			'selling_price.max' => 'Selling price cannot exceed 999,999.9999.',
			'description.max' => 'Description cannot exceed 1000 characters.',
		];
	}
}
