<?php

namespace App\Modules\HR\Recruitment\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /** @return array<string, mixed> */
    public function rules(): array
    {
        $settings = request()->attributes->get('career_settings');
        $rules = [
            'first_name' => ['required', 'string', 'max:120'],
            'last_name' => ['required', 'string', 'max:120'],
            'email' => ['required', 'email', 'max:191'],
            'phone' => ['nullable', 'string', 'max:60'],
            'nationality' => ['nullable', 'string', 'max:120'],
            'cover_letter' => ['nullable', 'string', 'max:5000'],
            'cv' => ['required', 'file', 'max:10240', 'mimes:pdf,doc,docx'],
        ];

        if ($settings && $settings->recaptcha_enabled && filled(config('services.recaptcha.secret_key'))) {
            $rules['g-recaptcha-response'] = ['required', 'string'];
        } else {
            $rules['g-recaptcha-response'] = ['nullable', 'string'];
        }

        return $rules;
    }
}
