<?php

namespace App\Http\Requests\Api\V1;

use Illuminate\Foundation\Http\FormRequest;

/**
 * Send a single WhatsApp message. Scramble reads these rules to document the
 * request body. Supports text, media (by URL) and location; template/bulk
 * sends use the /templates + /broadcasts endpoints.
 */
class SendMessageRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true; // api-key middleware already authenticated the workspace
    }

    public function rules(): array
    {
        return [
            // Recipient phone in international format (digits, E.164). Required.
            'to'          => ['required', 'string', 'max:32'],
            // Sending device id (optional — defaults to the workspace's primary).
            'device_id'   => ['nullable', 'integer'],
            // Message type. Defaults to "text".
            'type'        => ['nullable', 'in:text,image,video,document,location'],
            // Text body (required for text; used as caption for media).
            'text'        => ['nullable', 'string', 'max:4096'],
            // Public media URL (for image/video/document types).
            'media_url'   => ['nullable', 'url', 'max:2048'],
            // Location (when type=location).
            'latitude'    => ['nullable', 'numeric', 'between:-90,90'],
            'longitude'   => ['nullable', 'numeric', 'between:-180,180'],
        ];
    }
}
