<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Repositories\HomePageSliderRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class UserListingController extends Controller
{

    public function userList()
    {

        $id = Auth::id();
        $get_user_listing = User::query()->where('id', '!=', $id)->orderBy('id', 'DESC')->get();
        return view('admin.user_listing.index', compact('get_user_listing'));
    }

    public function userStatus(Request $request, $id)
    {
        $user = User::find($id);

        if ($request->has('status')) {
            $user->status = 'active';
            $message = 'User has been activated successfully!';
            $messageType = 'success';
        } else {
            $user->status = 'blocked';
            $message = 'User has been blocked.';
            $messageType = 'error';
        }

        if ($user->save()) {
            return redirect()->back()->with($messageType, $message);
        } else {
            // Handle failure to save (optional)
            return redirect()->back()->with('error', 'There was an issue updating the user status.');
        }
    }
}
