<?php

namespace App\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class PhoneNumber implements ValidationRule
{
    public function validate(string $attribute, mixed $value, Closure $fail): void
    {
        if (blank($value)) {
            return;
        }

        try {
            new \App\ValueObjects\PhoneNumber($value);
        } catch (\Throwable) {
            $fail("The :attribute is not a valid phone number.");
        }
    }
}