<?php
/**
 * Registry Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @package     bplan-base/globals
 * @subpackage  Registries
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 Wassilios Meletiadis <https://www.bplan-solutions.de/>
 * /Δ\
 */

namespace BplanBase\Globals\Registries;


/**
 * Registry Class
 *
 * @version     2.0.0 / 2025-03-01
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class LocationTypeRegistry
{


/* +++ CLASS CONSTANTS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT MEMBERS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ CLASS MEMBERS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     * @var     array $types
     */
    protected static array $types = [];


/* +++ OBJECT METHODS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ CLASS METHODS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     *
     * @return      array
     *
     * @version     1.0.0 / 2025-06-17
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function all(): array
    {
        return static::$types;

    } // all()


    /**
     *
     * @return      bool
     *
     * @version     1.0.0 / 2025-06-17
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function exists(string $name): bool
    {
        return isset(static::$types[$name]);

    } // exists()


    /**
     *
     * @return      array
     *
     * @version     1.0.0 / 2025-06-17
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function names(): array
    {
        ksort(static::$types);

        return array_keys(static::$types);

    } // names()


    /**
     *
     * @param       string $name
     *
     * @return      array
     *
     * @version     1.0.0 / 2026-03-01
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function getSubTypes(string $name): array
    {
        return static::$types[$name]['sub-types'];

    } // getSubTypes()


    /**
     *
     * @param       string $name
     *
     * @return      boolean
     *
     * @version     1.0.0 / 2025-03-01
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function isInternal(string $name): bool
    {
        return static::$types[$name]['is-internal'];

    } // isInternal()


    /**
     *
     * @param       string $name
     *
     * @param       array $subTypes
     *
     * @param       bool $internal
     *
     * @return      void
     *
     * @version     2.0.0 / 2025-03-01
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function register(string $name, array $subTypes = [], bool $internal = false): void
    {
        if (!isset(static::$types[$name])) {
            static::$types[$name] = [
                'is-internal' => $internal,
                'sub-types' => array_combine($subTypes, $subTypes),
                'value' => $name
            ];
        } else {
            if (!empty($subTypes)) {
                foreach ($subTypes as $subType) {
                    static::$types[$name]['sub-types'][$subType] = $subType;
                }
            }
        }
    } // register()


    /**
     *
     * @return      string|null
     *
     * @version     1.1.0 / 2025-03-01
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function value(string $name): string|null
    {
        return static::$types[$name]['value'] ?? null;

    } // value()


    /**
     *
     * @return      array
     *
     * @version     1.1.0 / 2025-03-01
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function values(): array
    {
        ksort(static::$types);

        return array_column(static::$types, 'value');

    } // values()


} // class LocationTypeRegistry {}
