<?php

namespace App\Http\Requests\Member;

use Illuminate\Foundation\Http\FormRequest;

// ══════════════════════════════════════════════════════════════════
//  InPractice — StoreDocumentRequest
//  Location: app/Http/Requests/Member/StoreDocumentRequest.php
//
//  Validates the Share Knowledge PDF upload form.
//
//  File rules (Bible):
//    - PDF only — mimes:pdf
//    - Max 10MB — max:10240
//    - Stored as UUID filename on disk — never original filename
//
//  Content rules:
//    - title_en required
//    - title_ar optional
//    - description optional
//    - document_category: report | template | guide | news | other
//    - hub_id must exist
//    - sector_id optional
//    - visibility: all | hub
//    - tags: optional array, max 5
// ══════════════════════════════════════════════════════════════════

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

    public function rules(): array
    {
        return [
            'file'              => ['required', 'file', 'mimes:pdf', 'max:10240'],
            'title_en'          => ['required', 'string', 'min:3', 'max:255'],
            'title_ar'          => ['nullable', 'string', 'min:3', 'max:255'],
            'description_en'    => ['nullable', 'string', 'max:1000'],
            'description_ar'    => ['nullable', 'string', 'max:1000'],
            'document_category' => ['required', 'in:report,template,guide,news,other'],
            'hub_id'            => ['required', 'integer', 'exists:hubs,id'],
            'sector_id'         => ['nullable', 'integer', 'exists:sectors,id'],
            'visibility'        => ['required', 'in:all,hub'],
            'language'          => ['required', 'in:en,ar'],
            'tags'              => ['nullable', 'array', 'max:5'],
            'tags.*'            => ['string', 'max:30'],
        ];
    }

    public function messages(): array
    {
        return [
            'file.required'              => __('documents.file_required'),
            'file.mimes'                 => __('documents.file_must_be_pdf'),
            'file.max'                   => __('documents.file_too_large'),
            'title_en.required'          => __('documents.title_required'),
            'document_category.required' => __('documents.category_required'),
            'document_category.in'       => __('documents.category_invalid'),
            'hub_id.required'            => __('common.hub_required'),
            'hub_id.exists'              => __('common.hub_invalid'),
        ];
    }
}
