<?php

namespace App\Http\Controllers;

use App\Models\AchievementCategory;
use App\Http\Requests\StoreAchievementCategoryRequest;
use App\Http\Requests\UpdateAchievementCategoryRequest;

class AchievementCategoryController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $achievementCategories = AchievementCategory::orderBy('created_at', 'desc')->get();
        return view('admin.achievement-category.index', compact('achievementCategories'));
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(StoreAchievementCategoryRequest $request)
    {
        $data = $request->validated();

        AchievementCategory::create($data);
        return redirect()->route('achievementcategories.index')->with('success', 'Achievement category created successfully');
    }

    /**
     * Display the specified resource.
     */
    public function show(AchievementCategory $achievementCategory)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(AchievementCategory $achievementcategory)
    {
        return view('admin.achievement-category.edit', compact('achievementcategory'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(UpdateAchievementCategoryRequest $request, AchievementCategory $achievementcategory)
    {
        $data = $request->validated();

        $achievementcategory->update($data);
        return redirect()->route('achievementcategories.index')->with('success', 'Achievement category updated successfully');
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(AchievementCategory $achievementcategory)
    {
        $achievementcategory->delete();
        return redirect()->route('achievementcategories.index')->with('success', 'Achievement category deleted successfully.');
    }
}
