<?php
namespace nur\sery\wip\schema;

use nur\sery\wip\schema\types\IType;
use nur\sery\wip\schema\types\Registry;
use nur\sery\wip\schema\types\tarray;
use nur\sery\wip\schema\types\tbool;
use nur\sery\wip\schema\types\tcallable;
use nur\sery\wip\schema\types\tcontent;
use nur\sery\wip\schema\types\tfloat;
use nur\sery\wip\schema\types\tint;
use nur\sery\wip\schema\types\tkey;
use nur\sery\wip\schema\types\tmixed;
use nur\sery\wip\schema\types\tpkey;
use nur\sery\wip\schema\types\traw;
use nur\sery\wip\schema\types\trawstring;
use nur\sery\wip\schema\types\tstring;
use nur\sery\wip\schema\types\ttext;

/**
 * Class types: classe outil pour gérer le registre de types
 */
class types {
  /** @var Registry */
  private static $registry;

  static function registry(): Registry {
    if (self::$registry === null) {
      self::$registry = new Registry();
    }
    return self::$registry;
  }

  static function get(bool $nullable, ?string $name, ?array $args=null, ?array $definition=null): IType {
    return self::registry()->get($nullable, $name, $args, $definition);
  }

  static function rawstring(bool $nullable=true): trawstring { return self::get($nullable, "rawstring"); }
  static function string(bool $nullable=true): tstring { return self::get($nullable, "string"); }
  static function text(bool $nullable=true): ttext { return self::get($nullable, "text"); }
  static function bool(bool $nullable=true): tbool { return self::get($nullable, "bool"); }
  static function int(bool $nullable=true): tint { return self::get($nullable, "int"); }
  static function float(bool $nullable=true): tfloat { return self::get($nullable, "float"); }
  static function array(bool $nullable=true): tarray { return self::get($nullable, "array"); }
  static function callable(bool $nullable=true): tcallable { return self::get($nullable, "callable"); }
  static function raw(bool $nullable=true): traw { return self::get($nullable, "raw"); }
  static function mixed(bool $nullable=true): tmixed { return self::get($nullable, "mixed"); }
  static function key(bool $nullable=true): tkey { return self::get($nullable, "key"); }
  static function pkey(bool $nullable=true): tpkey { return self::get($nullable, "pkey"); }
  static function content(bool $nullable=true): tcontent { return self::get($nullable, "content"); }
}
