<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Complaints;
use Illuminate\Http\Request;

class AdminComplaintsController extends Controller
{
    public function ComplaintsManagement()
    {
        $complaints = Complaints::with(['user'])->orderBy('id', 'DESC')->latest()->paginate(10);
        return view('adminDashboard.complaints-management', compact('complaints'));
    }

    public function ComplaintReply(Request $request)
    {
        $request->validate([
            'id' => 'required',
            'reply' => 'required'
        ]);
        Complaints::where(['id' => $request->id])->update([
            'reply' => $request->reply,
            'status' => 1
        ]);
        return redirect()->back();
    }

    public function DeleteComplaint($id)
    {
        Complaints::where(['id' => $id])->delete();
        return redirect()->back();
    }
}
