<?php

namespace App\Http\Requests\File;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        $maxSize = $this->input('category') === 'customer-image' ? 500 : 20480;

        return [
            'file' => [
                'required',
                'file',
                "max:{$maxSize}",
                'mimes:jpg,jpeg,png,webp,gif,pdf,doc,docx,xls,xlsx,csv,txt,zip',
            ],
            'category' => ['nullable', 'string', 'max:80', 'regex:/^[a-z0-9_-]+$/'],
        ];
    }

    public function messages(): array
    {
        return [
            'file.max' => $this->input('category') === 'customer-image'
                ? 'Gambar customer maksimal 500 KB setelah kompresi.'
                : 'Ukuran file maksimal 20 MB.',
            'file.mimes' => 'Jenis file tidak didukung.',
            'category.regex' => 'Kategori hanya boleh berisi huruf kecil, angka, garis bawah, atau tanda hubung.',
        ];
    }
}
