<?php

namespace App\Http\Requests;

use App\Services\IcNumberService;
use Illuminate\Foundation\Http\FormRequest;

class ParticipantStoreRequest extends FormRequest
{
    public function authorize(): bool
    {
        return auth()->check();
    }

    public function rules(): array
    {
        return [
            'full_name' => ['required', 'string', 'max:255'],
            'ic_number' => [
                'required',
                'string',
                function ($attribute, $value, $fail) {
                    if (! app(IcNumberService::class)->validate($value)) {
                        $fail('Nombor kad pengenalan mestilah mempunyai 12 digit.');
                    }
                },
            ],
            'participant_number' => ['nullable', 'string', 'max:50'],
            'category' => ['nullable', 'string', 'max:100'],
            'email' => ['nullable', 'email', 'max:255'],
            'phone_number' => ['nullable', 'string', 'max:20'],
            'is_active' => ['boolean'],
        ];
    }

    public function messages(): array
    {
        return [
            'full_name.required' => 'Nama peserta diperlukan.',
            'ic_number.required' => 'Nombor kad pengenalan diperlukan.',
        ];
    }
}
