<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\StoreBonusRequest;
use App\Models\Bonus;
use Inertia\Inertia;
use Inertia\Response;

class BonusController extends Controller
{
    public function index(): Response
    {
        return Inertia::render('Admin/Payroll/Bonuses/Index', [
            'bonuses' => Bonus::withCount('generations')->get(),
        ]);
    }

    public function store(StoreBonusRequest $request)
    {
        Bonus::create($request->validated());

        return back()->with('success', 'Bonus created successfully.');
    }

    public function update(StoreBonusRequest $request, Bonus $bonus)
    {
        $bonus->update($request->validated());

        return back()->with('success', 'Bonus updated successfully.');
    }

    public function destroy(Bonus $bonus)
    {
        $bonus->delete();

        return back()->with('success', 'Bonus deleted successfully.');
    }
}
