<?php

namespace App\Http\Controllers\Dashboard\PartnerRequest;

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

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

    public function show($id)
    {
        $partnerRequest = PartnerRequest::findOrFail($id);
        return view('dashboard.partners.requests.show', compact('partnerRequest'));
    }

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

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

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