<?php

namespace App\Http\Requests;

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

class UpdateLaundrySaleCategoryRequest extends FormRequest
{
    public function authorize(): bool
    {
        $cat = $this->route('laundrySaleCategory');

        return $cat && $this->user()?->can('update', $cat);
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        $id = $this->route('laundrySaleCategory')?->id;

        return [
            'code' => ['sometimes', 'required', 'string', 'max:64', Rule::unique('laundry_sale_categories', 'code')->ignore($id)],
            'name' => ['sometimes', 'required', 'string', 'max:255'],
            'sort_order' => ['nullable', 'integer', 'min:0'],
            'is_active' => ['sometimes', 'boolean'],
        ];
    }
}
