<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class ReadonlyOwner
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        if (auth()->check()) {
            if (auth()->user()->phone == '09999999999') {
                if ($request->method() == 'POST' || $request->method() == 'PUT' || $request->method() == 'PATCH' || $request->method() == 'DELETE') {
                    return redirect()->back()->withErrors([__('messages.sentence.readonly_owner_system')]);
                }
            }
        }

        return $next($request);
    }
}
