<?php

namespace App\Http\Controllers;

use App\Models\Complaints;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ComplaintsController extends Controller
{
    public function Complaints()
    {
        $complaints = Complaints::where(['user_id' => Auth::user()->id])->latest()->get();
        return view('userDashboard.complaints', compact('complaints'));
    }

    public function AddComplaint()
    {
        return view('userDashboard.addComplaint');
    }

    public function SubmitComplaint(Request $request)
    {
        $request->validate([
            'type' => 'required',
            'whatsapp' => 'required',
            'description' => 'required'
        ]);

        $complaint = new Complaints();
        $complaint->user_id = Auth::user()->id;
        $complaint->type = $request->type;
        $complaint->whatsapp = $request->whatsapp;
        $complaint->description = $request->description;
        $complaint->save();

        return redirect('/user/complaints');
    }
}
