<?php
 
namespace App\Rules;

use App\Models\Prefixes;
use Illuminate\Contracts\Validation\Rule;
use Exception;
use Illuminate\Support\Facades\Auth;

class AllowedPrefixIdentity implements Rule
{

    public function passes($attribute, $value)
    {

        try {
            return Prefixes::getOrganisationHasPrefix(Auth::user()->organisation_id, $value) !== false;
        }
        catch(Exception $ex) {
            return false;
        }

    }

    public function message()
    {
        return 'The :attribute must correlate to a prefix that the current user is allowed to use - This could mean subtenanted, or owned.';
    }
}