<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'recipients' => ['required', 'array', 'min:1'],
            'recipients.*.phone' => ['required', 'string', 'regex:/^[\+]?[0-9]{9,15}$/'],
            'recipients.*.name' => ['nullable', 'string', 'max:191'],
            'message' => ['required', 'string', 'max:1600'],
            'template_id' => ['nullable', 'integer', 'exists:sms_templates,id'],
            'scheduled_at' => ['nullable', 'date', 'after:now'],
            'sender_id_name' => ['nullable', 'string', 'max:50'],
        ];
    }

    public function messages(): array
    {
        return [
            'recipients.required' => 'Please select at least one recipient.',
            'recipients.*.phone.regex' => 'Please enter a valid phone number.',
            'message.required' => 'Please enter your message.',
            'message.max' => 'Message is too long. Maximum 1600 characters.',
            'scheduled_at.after' => 'Scheduled time must be in the future.',
        ];
    }
}
