<?php

namespace App\Http\Controllers;

use App\Models\PolicyCategory;
use App\Http\Requests\StorePolicyCategoryRequest;
use App\Http\Requests\UpdatePolicyCategoryRequest;
use Illuminate\Auth\Events\Validated;

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

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

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

        PolicyCategory::create($data);
        return redirect()->route('policycategories.index')->with('success', 'Policy category created successfully');
    }

    /**
     * Display the specified resource.
     */
    public function show(PolicyCategory $policyCategory)
    {
        //
    }

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

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

        $policycategory->update($data);
        return redirect()->route('policycategories.index')->with('success', 'Policy category updated successfully');
    }

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