<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\AdminAccount\StoreRequest;
use App\Http\Requests\AdminAccount\UpdateRequest;
use App\Models\Admin;
use Illuminate\Http\Request;

class AdminController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $admins = Admin::orderBy('id' , 'DESC')->paginate(10);
        return view('Admin.Admin.index', compact('admins'));
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        return view('Admin.Admin.add');
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(StoreRequest $request)
    {
        Admin::create($request->handleRequest());
        return redirect()->route('admin-account.index')->with('success_message' , 'Admin Successfully Created!');
    }

    /**
     * Display the specified resource.
     */
    public function show(Admin $admin)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit($id)
    {

        $admin = Admin::findOrFail($id);
        return view('Admin.Admin.edit',  compact('admin'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(UpdateRequest $request, $id)
    {
        $admin = Admin::findOrFail($id);
        $admin->update($request->handleRequest());
        return redirect()->route('admin-account.index')->with('success_message' , 'Admin Successfully Updated!');
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy($id)
    {
        Admin::findOrFail($id)->delete();
        return redirect()->route('admin-account.index')->with('success_message' , 'Admin Successfully Deleted!');
    }
}
