<?php

namespace App\Http\Requests;

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

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

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

        return [
            'name' => ['required', 'string', 'max:255'],
            'sku' => [
                'nullable', 'string', 'max:100',
                Rule::unique('items', 'sku')
                    ->where('business_id', Business::currentId())
                    ->ignore($itemId),
            ],
            'hs_code' => ['required', 'string', 'max:20'],
            'uom' => ['required', 'string', 'max:50'],
            'default_rate' => ['required', 'string', 'max:20'],
            'default_sale_type' => ['nullable', 'string', 'max:255'],
            'default_price_excl_st' => ['required', 'numeric', 'min:0'],
            'sro_schedule_no' => ['nullable', 'string', 'max:50'],
            'sro_item_serial_no' => ['nullable', 'string', 'max:50'],
            'is_active' => ['boolean'],
        ];
    }
}
