<?php

namespace App\Modules\HR\Attendance\Requests;

use App\Modules\HR\Attendance\Support\BiometricApiType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreBiometricDeviceRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('attendance.manage') ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:160'],
            'brand' => ['nullable', 'string', 'max:80'],
            'ip_address' => ['nullable', 'ip'],
            'port' => ['nullable', 'integer', 'min:1', 'max:65535'],
            'api_type' => ['required', 'string', Rule::in([
                BiometricApiType::GENERIC,
                BiometricApiType::ZKTECO,
                BiometricApiType::SUPREMA,
                BiometricApiType::REST_WEBHOOK,
            ])],
        ];
    }
}
