<?php

namespace App\Http\Requests\Students;

use App\Http\Requests\ApiFormRequest;

class StudentAssignClassRequest extends ApiFormRequest
{
    protected function prepareForValidation(): void
    {
        $value = $this->input('class_section_id');
        if (is_string($value)) {
            $parts = preg_split('/[,\s]+/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: [];
            $this->merge(['class_section_id' => $parts]);
        }
    }

    public function rules(): array
    {
        return [
            'student_id' => ['required', 'integer', 'min:1'],
            'class_section_id' => ['required', 'array', 'min:1'],
            'class_section_id.*' => ['integer', 'min:1'],
            'is_event_only' => ['nullable', 'boolean'],
        ];
    }
}
