<?php

namespace App\Http\Requests;

use App\Models\Attachment;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\File;

class StoreAttachmentRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', Attachment::class) ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'file' => [
                'required',
                File::types([
                    'pdf', 'jpg', 'jpeg', 'png', 'gif', 'webp',
                    'doc', 'docx', 'xls', 'xlsx', 'txt', 'csv',
                ])->max(51200),
            ],
            'description' => ['nullable', 'string', 'max:500'],
        ];
    }
}
