<?php

namespace App\Http\Requests\PublicSite;

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

/**
 * Public candidate registration (§164). Deliberately narrower than the staff
 * form: a stranger on the internet supplies only what a candidate would know
 * about themselves, and nothing that steers the recruitment process.
 */
class CandidateRegistrationRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'full_name' => ['required', 'string', 'max:255'],
            'father_name' => ['nullable', 'string', 'max:255'],
            'mother_name' => ['nullable', 'string', 'max:255'],
            'gender' => ['nullable', Rule::in(['male', 'female', 'other'])],
            'date_of_birth' => ['required', 'date', 'before:-16 years'],
            'marital_status' => ['nullable', Rule::in(['single', 'married', 'divorced', 'widowed'])],

            'national_id' => ['nullable', 'string', 'max:50'],
            'passport_number' => ['nullable', 'string', 'max:50'],
            'passport_expiry_date' => ['nullable', 'date', 'after:today'],

            'mobile' => ['required', 'string', 'max:32'],
            'whatsapp' => ['nullable', 'string', 'max:32'],
            'email' => ['nullable', 'email', 'max:255'],
            'present_address' => ['nullable', 'string', 'max:1000'],
            'district' => ['nullable', 'string', 'max:100'],

            'occupation' => ['nullable', 'string', 'max:120'],
            'desired_occupation' => ['nullable', 'string', 'max:120'],
            'experience_years' => ['nullable', 'integer', 'between:0,60'],
            'education_level' => ['nullable', 'string', 'max:120'],
            'skills' => ['nullable', 'string', 'max:2000'],
            'preferred_country' => ['nullable', 'string', 'max:60'],
            'has_overseas_experience' => ['nullable', 'boolean'],
            'previous_country' => ['nullable', 'string', 'max:60'],

            // Optional job the candidate is applying against.
            'job_slug' => ['nullable', 'string', 'max:160'],

            // Explicit consent to hold and process their data (§105).
            'consent' => ['accepted'],
        ];
    }

    public function messages(): array
    {
        return [
            'date_of_birth.before' => 'Applicants must be at least 16 years old.',
            'consent.accepted' => 'Please confirm you agree to your details being processed.',
        ];
    }

    /** @return array<string, mixed> */
    public function candidateAttributes(): array
    {
        $data = $this->safe()->except(['job_slug', 'consent']);
        $data['source'] = 'website';

        return $data;
    }
}
