<?php

namespace App\Http\Requests\SelfPaced;

use Illuminate\Foundation\Http\FormRequest;

/**
 * StoreCourseBookRequest
 *
 * Validates course book PDF upload and fee configuration.
 *
 * Requirements: 9.3, 9.14
 */
class StoreCourseBookRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('manage self-paced book');
    }

    public function rules(): array
    {
        $maxSize = config('self-paced.book_max_size', 51200); // 50 MB in KB

        return [
            'book' => ['required', 'file', 'mimes:pdf', 'max:' . $maxSize],
            'book_fee' => ['nullable', 'numeric', 'min:0'],
        ];
    }

    public function messages(): array
    {
        return [
            'book.required' => 'Please select a PDF file',
            'book.mimes' => 'File must be PDF format',
            'book.max' => 'File size exceeds maximum allowed',
            'book_fee.numeric' => 'Book fee must be a number',
            'book_fee.min' => 'Book fee cannot be negative',
        ];
    }
}
