<?php

namespace App\Http\Controllers;

use App\Models\QuestionType;
use Illuminate\Http\Request;
use Illuminate\View\View;

class QuestionTypeController extends Controller
{
    public function index(): View
    {
        $types = QuestionType::query()
            ->orderBy('id', 'desc')
            ->paginate(20);

        return view('question-types.index', compact('types'));
    }

    public function create(): View
    {
        return view('question-types.create');
    }

    public function store(Request $request)
    {
        $validated = $request->validate([
            'name' => ['required', 'string', 'max:255'],
            'slug' => ['required', 'string', 'max:255', 'unique:question_types,slug'],
        ]);

        QuestionType::create($validated);

        return redirect()->route('question-types.index')->with('success', 'تمت إضافة نوع السؤال بنجاح.');
    }
}

