<?php

namespace Modules\MembershipApplication\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UploadMembershipApplicationDocumentRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    /**
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'type' => ['required', Rule::in(['ic_copy', 'photo', 'salary_slip', 'employer_letter'])],
            'file' => [
                'required',
                'file',
                'max:10240',
                Rule::when(
                    $this->input('type') === 'photo',
                    'mimes:jpg,jpeg,png',
                    'mimes:pdf,jpg,jpeg,png',
                ),
            ],
        ];
    }

    /**
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'type.required' => 'Jenis dokumen diperlukan.',
            'type.in' => 'Jenis dokumen tidak sah.',
            'file.required' => 'Fail diperlukan.',
            'file.mimes' => 'Format fail tidak disokong.',
            'file.max' => 'Saiz fail melebihi had maksimum 10MB.',
        ];
    }
}
