<?php

namespace App\Master\Http\Requests;

use App\Rules\MtcRoleRestriction;
use JetBrains\PhpStorm\ArrayShape;
use Mtc\MercuryDataModels\User;
use Stancl\Tenancy\Database\Concerns\CentralConnection;

class UpdateUserRoleOnSiteRequest extends SiteRequest
{
    use CentralConnection;

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    #[ArrayShape(['userId' => "string[]", 'role' => "string[]"])]
    #[\Override] public function rules()
    {
        $global = $this->getConnectionName();
        return [
            'userId' => [
                'required',
                "exists:$global.users,id",
            ],
            'role' => [
                'required',
                new MtcRoleRestriction(User::find($this->input('userId'))?->email ?? ''),
            ]
        ];
    }
}
