<?php

namespace App\Http\Controllers;

use App\Models\TrainingFeedback;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

class TrainingFeedbackController extends Controller
{
    public function index(): View
    {
        return view('pages.training-feedback');
    }

    public function store(Request $request): RedirectResponse
    {
        $data = $request->validate([
            'name' => ['nullable', 'string', 'max:120'],
            'email' => ['nullable', 'email', 'max:190'],
            'organization' => ['nullable', 'string', 'max:160'],
            'event_name' => ['nullable', 'string', 'max:160'],
            'training_date' => ['nullable', 'date'],
            'facilitator' => ['nullable', 'string', 'max:120'],
            'audience_segment' => ['nullable', 'string', 'max:80'],
            'content_satisfaction' => ['required', 'integer', 'between:1,5'],
            'trainer_expertise' => ['required', 'integer', 'between:1,5'],
            'scheduling_rating' => ['required', 'integer', 'between:1,5'],
            'scheduling_comment' => ['nullable', 'string', 'max:1000'],
            'trainer_personalization' => ['required', 'integer', 'between:1,5'],
            'trainer_advice' => ['nullable', 'string', 'max:1000'],
            'overall_experience' => ['required', 'integer', 'between:1,5'],
            'financial_mindset_impact' => ['nullable', 'string', 'max:3000'],
            'recommend_training' => ['nullable', 'string', 'max:1000'],
            'greatest_impact_topics' => ['nullable', 'array'],
            'greatest_impact_topics.*' => ['string'],
            'more_time_topics' => ['nullable', 'array'],
            'more_time_topics.*' => ['string'],
            'recommended_improvements' => ['nullable', 'string', 'max:3000'],
            'trainer_additional_feedback' => ['nullable', 'string', 'max:3000'],
        ]);

        TrainingFeedback::create($data);

        return back()->with('feedback_submitted', true);
    }
}
