<?php

namespace App\Http\Controllers\Dashboard\ServiceRequest;

use App\Http\Controllers\Controller as ExController;
use App\Models\ServiceRequest;
use Illuminate\Http\Request;

class Controller extends ExController
{
    public function index()
    {
        $requests = ServiceRequest::latest('id')->paginate(20);
        return view('dashboard.services.requests.index', compact('requests'));
    }

    public function show($id)
    {
        $serviceRequest = ServiceRequest::findOrFail($id);
        return view('dashboard.services.requests.show', compact('serviceRequest'));
    }

    public function update(Request $request, $id)
    {
        // validate request
        $request->validate([
            'status' => 'required|in:approved,rejected,closed,pending'
        ]);

        $serviceRequest = ServiceRequest::findOrFail($id);
        $serviceRequest->update([
            'status' => $request->status,
        ]);

        $this->info(trans('admin.messages.updated'));
        return redirect()->route('dashboard.service_requests.index');
    }
}
