<?php

namespace Modules\SystemCore\App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateCustomerDocumentRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'document_title' => ['required', 'string', 'max:255'],
            'document_number' => ['nullable', 'string', 'max:100'],
            'document_type' => ['nullable', 'string', 'max:50'],
            'document_file' => ['nullable', 'file', 'mimes:pdf,jpg,jpeg,png,doc,docx', 'max:10240'],
            'issue_date' => ['nullable', 'date'],
            'expiry_date' => ['nullable', 'date', 'after_or_equal:issue_date'],
            'notes' => ['nullable', 'string'],
            'is_active' => ['nullable', 'boolean'],
        ];
    }

    /**
     * Get custom error messages for validation rules.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'document_title.required' => __('Document title is required.'),
            'document_title.max' => __('Document title cannot exceed 255 characters.'),
            'document_number.max' => __('Document number cannot exceed 100 characters.'),
            'document_type.max' => __('Document type cannot exceed 50 characters.'),
            'document_file.file' => __('The uploaded file is invalid.'),
            'document_file.mimes' => __('Document must be a PDF, JPG, JPEG, PNG, DOC, or DOCX file.'),
            'document_file.max' => __('Document file size cannot exceed 10MB.'),
            'issue_date.date' => __('Issue date must be a valid date.'),
            'expiry_date.date' => __('Expiry date must be a valid date.'),
            'expiry_date.after_or_equal' => __('Expiry date must be after or equal to issue date.'),
        ];
    }
}
