<?php

namespace App\Http\Requests\Member;

use Illuminate\Foundation\Http\FormRequest;

// ══════════════════════════════════════════════════════════════════
//  InPractice — StoreForumPostRequest
//  Location: app/Http/Requests/Member/StoreForumPostRequest.php
//
//  Validates creating a new forum post.
//  hub_id must belong to a hub the member has joined.
//  Title 10–200 chars, body minimum 30 chars.
//  Tags optional array of strings (max 5 tags, each max 30 chars).
// ══════════════════════════════════════════════════════════════════

class StoreForumPostRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true; // auth middleware handles authentication
    }

    public function rules(): array
    {
        return [
            'hub_id'             => ['required', 'integer', 'exists:hubs,id'],
            'title'              => ['required', 'string', 'min:10', 'max:200'],
            'body'               => ['required', 'string', 'min:30'],
            'language'           => ['required', 'string', 'in:en,ar'],
            'visibility'         => ['required', 'string', 'in:all,hub'],
            'posted_as_nickname' => ['boolean'],
            'tags'               => ['nullable', 'array', 'max:5'],
            'tags.*'             => ['string', 'max:30'],
        ];
    }

    public function messages(): array
    {
        return [
            'hub_id.required'    => __('forum.validation_hub_required'),
            'hub_id.exists'      => __('forum.validation_hub_invalid'),
            'title.required'     => __('forum.validation_title_required'),
            'title.min'          => __('forum.validation_title_min'),
            'title.max'          => __('forum.validation_title_max'),
            'body.required'      => __('forum.validation_body_required'),
            'body.min'           => __('forum.validation_body_min'),
            'language.required'  => __('forum.validation_language_required'),
            'visibility.required'=> __('forum.validation_visibility_required'),
        ];
    }
}
