<?php

namespace App\Http\Requests\Api\V1;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * PATH 파라미터 {id}를 file_id로 자동 병합
     */
    protected function prepareForValidation(): void
    {
        $this->merge([
            'file_id' => $this->route('id'),
        ]);
    }

    public function rules(): array
    {
        return [
            'file_id' => 'required|integer|exists:files,id',
            'expiry_hours' => 'nullable|integer|min:1|max:168', // Max 7 days
        ];
    }

    public function messages(): array
    {
        return [
            'file_id.required' => __('error.file_id_required'),
            'file_id.exists' => __('error.file_not_found'),
            'expiry_hours.min' => __('error.expiry_hours_min'),
            'expiry_hours.max' => __('error.expiry_hours_max'),
        ];
    }
}
