<?php

namespace App\Http\Requests\SelfPaced;

use Illuminate\Foundation\Http\FormRequest;

/**
 * UpdateCourseSettingsRequest
 *
 * Validates course payment and fee configuration.
 *
 * Requirements: 2.8, 9.14, 10.2, 18.3
 */
class UpdateCourseSettingsRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('manage self-paced settings');
    }

    public function rules(): array
    {
        return [
            'payment_mode' => ['required', 'string', 'in:online,cash,both'],
            'registration_fee' => ['nullable', 'numeric', 'min:0'],
            'application_fee' => ['nullable', 'numeric', 'min:0'],
            'certificate_fee' => ['nullable', 'numeric', 'min:0'],
            'certificate_collection_mode' => ['required', 'string', 'in:self_download,hardcopy'],
            'book_fee' => ['nullable', 'numeric', 'min:0'],
            'exam_failure_fee' => ['nullable', 'numeric', 'min:0'],
        ];
    }

    public function messages(): array
    {
        return [
            'payment_mode.required' => 'Payment mode is required',
            'payment_mode.in' => 'Invalid payment mode',
            'registration_fee.numeric' => 'Registration fee must be a number',
            'registration_fee.min' => 'Registration fee cannot be negative',
            'application_fee.numeric' => 'Application fee must be a number',
            'application_fee.min' => 'Application fee cannot be negative',
            'certificate_fee.numeric' => 'Certificate fee must be a number',
            'certificate_fee.min' => 'Certificate fee cannot be negative',
            'book_fee.numeric' => 'Book fee must be a number',
            'book_fee.min' => 'Book fee cannot be negative',
            'exam_failure_fee.numeric' => 'Exam failure fee must be a number',
            'exam_failure_fee.min' => 'Exam failure fee cannot be negative',
        ];
    }
}
