<?php

namespace App\Http\Requests;

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

class StoreGarmentTypeRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', GarmentType::class) ?? false;
    }

    public function rules(): array
    {
        return [
            'code' => ['nullable', 'string', 'max:64', 'alpha_dash', Rule::unique('garment_types', 'code')],
            'name' => ['required', 'string', 'max:255'],
            'sort_order' => ['nullable', 'integer', 'min:0'],
            'is_active' => ['sometimes', 'boolean'],
            'default_load_type_id' => ['nullable', 'integer', 'exists:load_types,id'],
        ];
    }
}
