<?php

namespace Planaday\Utility\DataFilters\Validators;

class NotEmpty implements Validator {
	public function __construct(
		protected string $message = 'required field is missing'
	) {}

	/**
	 * @template T
	 * @param T $data
	 *
	 * @return string|true
	 */
	public function validate($data): string|bool {
		if ( $data !== null && empty( $data ) && is_bool( $data ) === false ) {
			return $this->message;
		}

		return true;
	}

	public function getName(): string {
		return 'not_empty';
	}
}