<?php

namespace App\Modules\HR\Recruitment\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    /** @return array<string, mixed> */
    public function rules(): array
    {
        return [
            'is_enabled' => ['nullable', 'boolean'],
            'portal_title' => ['nullable', 'string', 'max:180'],
            'portal_subtitle' => ['nullable', 'string', 'max:255'],
            'about_text' => ['nullable', 'string', 'max:5000'],
            'contact_email' => ['nullable', 'email', 'max:191'],
            'contact_phone' => ['nullable', 'string', 'max:60'],
            'seo_title' => ['nullable', 'string', 'max:180'],
            'seo_description' => ['nullable', 'string', 'max:320'],
            'seo_keywords' => ['nullable', 'string', 'max:255'],
            'recaptcha_enabled' => ['nullable', 'boolean'],
        ];
    }

    protected function prepareForValidation(): void
    {
        $this->merge([
            'is_enabled' => $this->boolean('is_enabled'),
            'recaptcha_enabled' => $this->boolean('recaptcha_enabled'),
        ]);
    }
}
