<?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;


use BplanBase\Globals\Console\Output;


/**
 * Registry Class
 *
 * @version     1.3.0 / 2026-04-19
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class SeederRegistry
{

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


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


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


    /**
     * @var     array $_seeders
     */
    private static array $_seeders = [];


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


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


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

        return self::$_seeders;

    } // get()


    /**
     *
     * @param       int|string $packageKey
     *
     * @param       string $package
     *
     * @param       string $class
     *
     * @version     1.0.0 / 2025-05-17
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function register(int|string $packageKey, string $package, string $class): void
    {
        self::$_seeders[$packageKey] = [
            'class' => $class,
            'package' => $package,
        ];
    } // register()


    /**
     *
     * @param       $Seeder
     *
     * @version     1.3.0 / 2026-04-19
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function run($Seeder)
    {
        $seeders = SeederRegistry::get();

        if (!empty($seeders)) {
            Output::registerStatusColor('DONE', 'green');
            Output::registerStatusColor('RUNNING', 'yellow');

            $Output = new Output();

            $Output->newline();

            foreach ($seeders as $packageKey => $seeder) {
                $text = 'Seeding package '.$packageKey.':['.$seeder['package'].']';

                $Output->statusMessage($text, 'RUNNING');

                $Seeder->call($seeder['class']);

                $Output->statusMessage($text, 'DONE');
            }
            $Output->newline();
        }
    } // run()

} // class SeederRegistry {}
