<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

/**
 * StoreDiscussionReplyRequest
 * 
 * Validation for creating a new discussion reply.
 * Used in DiscussionReplyController@store
 */
class StoreDiscussionReplyRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return auth()->check() && (
            auth()->user()->can('create discussion replies') ||
            auth()->user()->can('create discussions')
        );
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'content' => 'required|string|min:10|max:5000',
            'parent_id' => 'nullable|integer|exists:discussion_replies,id',
        ];
    }

    /**
     * Get custom validation messages.
     */
    public function messages(): array
    {
        return [
            'content.required' => 'Reply content is required.',
            'content.min' => 'Reply must be at least 10 characters long.',
            'content.max' => 'Reply cannot exceed 5000 characters.',
            'parent_id.exists' => 'The selected parent reply does not exist.',
        ];
    }
}
