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

namespace BplanBase\Globals\Database\Seeders;


use Illuminate\Database\Seeder;


/**
 * Seeder Class
 *
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class DatabaseSeeder extends Seeder
{


/* +++ TRAITS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */


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


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


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


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


    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        define('GLOBALS_BASE_PATH', str_replace('\\', '/', realpath(__DIR__.'/../..')));

        $env = strtolower(config('app.env'));

        $seeds = [];

        $seeds = [
            RegisterModuleSeeder::class,
            CountrySeeder::class,
            ExternalSystemSeeder::class,
            PrinterTypeSeeder::class,
            LocationTypeSeeder::class,
            /*
                @todo   Muss später entfernt werden und es muss eine bessere Lösung gefunden werden. Für Dev okay.
                        Bessere Variante für ein Produktivsystem: Token automatisch erzeugen und ins setup.log schreiben.
            */
            PersonalAccessTokenSeeder::class,

        ];
        if ($env === 'production' || config('globals.dev.seed-production')) {
            $seeds[] = Project\TenantSeeder::class;
            $seeds[] = Project\TenantLocaleSeeder::class;
            $seeds[] = Project\RoleSeeder::class;
            $seeds[] = Project\LocationSeeder::class;

            $seeds[] = SystemUserSeeder::class;

            if ($env !== 'production' && config('globals.dev.seed-production')) {
                $seeds[] = Dev\CombinedUserSeeder::class;
            }
            $seeds[] = Project\LanguageSeeder::class;
            $seeds[] = Project\UserSeeder::class;
            $seeds[] = Project\GlobalSettingSeeder::class;

        } elseif (str_starts_with($env, 'demo') === true) {
            $seeds[] = Project\TenantSeeder::class;
            $seeds[] = Project\TenantLocaleSeeder::class;
            $seeds[] = Project\RoleSeeder::class;
            $seeds[] = Project\LocationSeeder::class;

            $seeds[] = SystemUserSeeder::class;

            $seeds[] = Demo\CombinedTenantSeeder::class;
            $seeds[] = Demo\CombinedUserSeeder::class;
            $seeds[] = Dev\CombinedUserSeeder::class;

            $seeds[] = Project\LanguageSeeder::class;
            $seeds[] = Project\UserSeeder::class;
            $seeds[] = Project\GlobalSettingSeeder::class;

        } else {
            $seeds[] = Project\TenantSeeder::class;
            $seeds[] = Project\TenantLocaleSeeder::class;
            $seeds[] = Project\RoleSeeder::class;
            $seeds[] = Project\LocationSeeder::class;

            $seeds[] = SystemUserSeeder::class;
            $seeds[] = Dev\CombinedUserSeeder::class;

            $seeds[] = Project\LanguageSeeder::class;
            $seeds[] = Project\UserSeeder::class;
            $seeds[] = Project\GlobalSettingSeeder::class;

            /*
            **  EntityTypes seeden
            **
            **  Individual          -   Model, EntityType und Fields seeden. */
            // $seeds[] = EntityTypes\IndividualModelSeeder::class;
            // $seeds[] = EntityTypes\IndividualSeeder::class;
            // $seeds[] = EntityTypes\IndividualFieldSeeder::class;
            /*
            **  Individual.Employee -   EntityType und Fields seeden. */
            // $seeds[] = EntityTypes\IndividualEmployeeSeeder::class;
            // $seeds[] = EntityTypes\IndividualEmployeeFieldSeeder::class;

            /*
            **  Individual.Employee -   Daten seeden. */
            // $seeds[] = EntityTypes\IndividualEmployeeSeeder::class;
            // $seeds[] = EntityTypes\IndividualEmployeeFieldSeeder::class;
            // $seeds[] = Dev\EntityTypes\IndividualEmployeeDataSeeder::class;
        }
        $this->call($seeds);

    } // run()


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


    /**
     * @return      array
     *
     * @version     1.1.0 / 2026-04-19
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function loadConfig(): array
    {
        $env = strtolower(config('app.env'));

        $globalsSetup = [];
        $systemSetup  = ['System' => require GLOBALS_BASE_PATH.'/etc/setup/system.php'];

        if ($env === 'production') {
            $globalsSetup = $systemSetup + require base_path('etc/setup/globals.php');

        } elseif (str_starts_with($env, 'demo') === true) {
            $globalsSetup = $systemSetup + require base_path(GLOBALS_BASE_PATH.'/etc/setup/demo.php');

        } else {
            $globalsSetup = $systemSetup + require base_path('etc/setup/globals.php');
        }
        return $globalsSetup;

    } // loadConfig()


    /**
     * @return      array
     *
     * @version     1.0.0 / 2026-04-20
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function loadPackageConfig(string $vendorPackage, string $configFileName): array
    {
        $filePath = base_path('vendor/'.$vendorPackage.'/etc/setup/'.$configFileName.'.php');

        return require $filePath;

    } // loadPackageConfig()


} // class DatabaseSeeder extends Seeder
