<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

/**
 * UpdateDiscussionReplyRequest
 * 
 * Validation for updating an existing discussion reply.
 * Used in DiscussionReplyController@update
 */
class UpdateDiscussionReplyRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        if (!auth()->check()) {
            return false;
        }

        $reply = $this->route('reply');

        return auth()->user()->id === $reply->user_id ||
               auth()->user()->hasAnyRole(['Manager', 'Super Manager']) ||
               auth()->user()->can('edit discussion replies');
    }

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

    /**
     * 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.',
        ];
    }
}
