<?php
namespace nur\data\types;

class TriboolType extends BoolType {
  const TITLE = "valeur triléenne";

  const ALLOW_NULL = true;
  const FORMAT = self::OUINONNULL_FORMAT;

  static final function to_tribool($value): ?bool {
    return $value !== null? self::to_bool($value): null;
  }

  function isInstance($value, bool $strict=false): bool {
    return $value === null || is_bool($value);
  }

  function isUndef($value, $key=null): bool {
    if ($key !== null) {
      if (!is_array($value)) return $key === 0;
      return array_key_exists($key, $value);
    }
    return true;
  }

  function is3States(): bool {
    return true;
  }

  function get3States(): array {
    return [false, true, null];
  }

}
