<?php
namespace nulib\schema\types;

use nulib\schema\_scalar\ScalarSchema;
use nulib\schema\input\Input;
use nulib\schema\Result;
use nulib\schema\Schema;

class tmixed extends _tsimple {
  const NAME = "mixed";

  function getClass(): string {
    return "mixed";
  }

  function getMissingValue(?bool &$valid=null) {
    $valid = false;
    return null;
  }

  function getNullValue() {
    return null;
  }

  function isAvailable(Input $input, $valueKey): bool {
    return $input->isAvailable($valueKey);
  }

  public function isNull($value): bool {
    return $value === null;
  }

  function isValid($value, ?bool &$normalized=null): bool {
    $normalized = true;
    return true;
  }

  function parse(string $value) {
    return $value;
  }

  /**
   * @var ScalarSchema $schema
   */
  function normalize(&$value, Result $result, Schema $schema): bool {
    if (!$result->normalized) $result->setNormalized();
    return false;
  }

  function format($value, $format=null): string {
    return strval($value);
  }
}
