<?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 BplanBase\Globals\Models\Country;
use BplanBase\Globals\Models\Location;
use BplanBase\Globals\Models\LocationType;
use BplanBase\Globals\Models\Role;
use BplanBase\Globals\Models\Tenant;
use BplanBase\Globals\Models\TenantLocale;
use BplanBase\Globals\Models\TenantRecord;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;


/**
 * Seeder Class
 *
 * Seed system tenant with tenant record, locales and roles.
 *
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class CombinedTenantSeeder extends Seeder
{

    /**
     * Run the database seeds.
     *
     * @return void
     *
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function run()
    {
        $date = date('Y-m-d H:i:s');

        Tenant::insert([
            [
                'id' => 1,
                'uuid' => '00000000-0000-0000-0000-000000000000',
                'active' => 1,
                'created_at' => $date,
                'updated_at' => $date,
                'identifier' => 'System',
                'master_id' => null,
                'path' => '00',
            ],

        ]);
        $Country = Country::where('iso3166_alpha_2', '=', 'DE')->first();

        // System-Tenant
        $Tenant = Tenant::where('identifier', 'System')->first();

        TenantRecord::insert([
            [
                'id' => $Tenant->id,
                'uuid' => $Tenant->uuid,
                'created_at' => $date,
                'updated_at' => $date,
                'city' => 'Köln',
                'company' => 'bplan-solutions GmbH & Co. KG',
                'country_id' => $Country->id,
                'description' => NULL,
                'email' => 'core@bplan-solutions.de',
                'home_page' => 'https://www.bplan-solutions.de/',
                'house_number' => '22',
                'phone_number' => '22039898980',
                'phone_number_country_code' => '+49',
                'short_name' => 'bplan-solutions',
                'street' => 'Max-Reichpietsch-Strasse',
                'zip_code' => '51147',
            ],
        ]);

        TenantLocale::insert([
            [
                'uuid' => Str::uuid(),
                'active' => 1,
                'created_at' => $date,
                'key_index' => 1,
                'locale' => 'de',
                'main' => 1,
                'tenant_id' => $Tenant->id,
            ], [
                'uuid' => Str::uuid(),
                'active' => 1,
                'created_at' => $date,
                'key_index' => 2,
                'locale' => 'en',
                'main' => 0,
                'tenant_id' => $Tenant->id,
            ], [
                'uuid' => Str::uuid(),
                'active' => 1,
                'created_at' => $date,
                'key_index' => 3,
                'locale' => 'fr',
                'main' => 0,
                'tenant_id' => $Tenant->id,
            ],
        ]);

        Role::insert([
            [
                'uuid' => Str::uuid(),
                'active' => 1,
                'created_at' => $date,
                'updated_at' => $date,
                'identifier' => 'Admin',
                'internal' => 1,
                'labels' => '{"de": "Administrator", "en": "Administrator", "it": "Amministratore"}',
                'tenant_id' => $Tenant->id,
            ],
        ]);
        $locationLabels = [
            'de' => 'Zentrale',
            'en' => 'Main Office',
            'it' => 'Centrale',
        ];
        Location::insert([
            [
                'uuid'             => Str::uuid(),
                'active'           => 1,
                'created_at'       => $date,
                'updated_at'       => $date,
                'address_addition' => null,
                'city'             => 'Köln',
                'house_number'     => 22,
                'labels'           => json_encode($locationLabels),
                'location_type_id' => LocationType::where('identifier', '=', 'Site') //->where('sub_type', '=', 'Headquarters')
                    ->first()->id,

                'master_id' => null,
                'path'      => '00',
                'street'    => 'Max-Reichpietsch-Strasse',
                'sub_type'  => 'Headquarters',
                'tenant_id' => $Tenant->id,
                'top_level' => 1,
                'zip_code'  => '51147',
            ]
        ]);

    } // run()

} // class CombinedTenantSeeder extends Seeder {}
