<?php

namespace App\Http\Requests\Messaging;

use Illuminate\Foundation\Http\FormRequest;

class StoreConversationRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    public function rules(): array
    {
        return [
            'type' => 'required|in:direct,group',
            'recipient_id' => 'required_if:type,direct|integer|exists:users,id',
            'participant_ids' => 'required_if:type,group|array|min:2',
            'participant_ids.*' => 'integer|exists:users,id',
            'title' => 'required_if:type,group|nullable|string|max:120',
            'body' => 'required|string|max:5000',
            'client_temp_id' => 'nullable|string|max:120',
        ];
    }
}
