<?php

namespace App\Http\Requests;

use App\Http\Controllers\Admin\UserManageTrait;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Foundation\Http\FormRequest;

class BackendUserDelete extends FormRequest
{
    use UserManageTrait;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        $userId = $this->input('id');
        return !empty($userId) && !$this->_isOwner($userId);
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'id' => 'integer'
        ];
    }

    protected function failedAuthorization()
    {
        throw new AuthorizationException('You cannot delete your own user.');
    }
}
