<?php

namespace App\Http\Requests;

use App\Models\Student;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        return [
            'family_id' => ['required', 'exists:families,id'],
            'academic_session_id' => ['nullable', 'exists:academic_sessions,id'],
            'class_id' => ['nullable', 'exists:classes,id'],
            'section_id' => ['nullable', 'exists:sections,id'],
            'group' => ['nullable', 'string', 'max:50'],

            'name' => ['required', 'string', 'max:150'],
            'name_urdu' => ['nullable', 'string', 'max:150'],
            'photo' => ['nullable', 'image', 'mimes:jpg,jpeg,png,webp', 'max:2048'],
            'gender' => ['required', Rule::in(['male', 'female', 'other'])],
            'date_of_birth' => ['nullable', 'date', 'before:today'],
            'place_of_birth' => ['nullable', 'string', 'max:120'],
            'religion' => ['nullable', 'string', 'max:50'],
            'nationality' => ['nullable', 'string', 'max:50'],
            'b_form_number' => ['nullable', 'string', 'max:30'],
            'blood_group' => ['nullable', 'string', 'max:5'],

            'registration_number' => ['nullable', 'string', 'max:50'],
            'roll_number' => ['nullable', 'string', 'max:50'],
            'gr_number' => ['nullable', 'string', 'max:50'],
            'admission_date' => ['nullable', 'date'],
            'status' => ['nullable', Rule::in(Student::STATUSES)],

            'allergies' => ['nullable', 'string', 'max:500'],
            'medical_conditions' => ['nullable', 'string', 'max:500'],
            'disability_info' => ['nullable', 'string', 'max:500'],
            'medical_notes' => ['nullable', 'string', 'max:1000'],

            'transport_route_id' => ['nullable', 'exists:transport_routes,id'],
            'transport_stop_id' => ['nullable', 'exists:transport_stops,id'],
            'pickup_point' => ['nullable', 'string', 'max:150'],

            'fees' => ['nullable', 'array'],
            'fees.*' => ['nullable', 'numeric', 'min:0'],

            'generate_challan' => ['nullable', 'boolean'],
        ];
    }
}
