<?php

namespace App\Http\Requests;

use App\Enums\Role;
use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StaffUpdateRequest extends FormRequest
{
    public function authorize(): bool
    {
        $organization = $this->attributes->get('current_organization');
        return $this->user()->can('manageStaff', [User::class, $organization]);
    }

    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'min:3', 'max:150'],
            'display_name' => ['required', 'string', 'max:255'],
            'role' => ['nullable', 'string', Rule::in(Role::assignableValues())],
        ];
    }

    public function attributes(): array
    {
        return [
            'name' => 'Họ & tên',
            'display_name' => 'Tên hiển thị',
            'role' => 'Vai trò',
        ];
    }
}
