<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

use App\Models\Address;

class TwoByteIntegerWithZero implements Rule
{
	/**
	 * Determine if the validation rule passes.
	 * This will check that a number used for zone, net, host is between 1 and Address::ADDRESS_FIELD_MAX.
	 *
	 * @param string $attribute
	 * @param mixed $value
	 * @return bool
	 */
	public function passes($attribute,$value)
	{
		return (is_numeric($value) && ($value >= 0) && ($value < Address::ADDRESS_FIELD_MAX));
	}

	/**
	 * Get the validation error message.
	 *
	 * @return string
	 */
	public function message()
	{
		return sprintf('The number must be between 1 and %d.',Address::ADDRESS_FIELD_MAX);
	}
}