<?php
/**
 * Observer Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @version     STUB: 1.3.1
 * @generated   2026-04-14 17:09:34
 * @package     bplan-base/globals
 * @subpackage  Observers
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @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\Observers;


use BplanBase\Globals\Support\Str as StringHelper;
use BplanBase\Globals\Models\TenantRecord;
use Illuminate\Support\Str;


/**
 * Observer Class
 *
 * @version     1.0.0 / 2026-04-14
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class TenantRecordObserver
{


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


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


    /**
     * @var     string
     */
    const MODEL_CLASS = TenantRecord::class;


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


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


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


    /**
     * Handle the Models "created" event
     *
     * When a new model is saved for the first time, the creating and created
     * events will dispatch.
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function created(TenantRecord $Model): void
    {
        //
    } // created()


    /**
     * Handle the Models "creating" event
     *
     * When a new model is saved for the first time, the creating and created
     * events will dispatch.
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.1.0 / 2026-05-24
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function creating(TenantRecord $Model): void
    {
        $Model->uuid = Str::uuid();

        $Model->email = StringHelper::normalizeEmail($Model->email);

        if (!empty($Model->mobile_phone_number_country_code)) {
            $mobilePhoneNumber = $Model->mobile_phone_number_country_code.str_replace($Model->mobile_phone_number_country_code, '', $Model->mobile_phone_number);
        } else {
            $mobilePhoneNumber = $Model->mobile_phone_number;
        }
        $mobilePhoneNumber = StringHelper::explodePhoneNumber(StringHelper::normalizePhoneNumber($mobilePhoneNumber));

        $Model->mobile_phone_number = $mobilePhoneNumber['phone-number'];
        $Model->mobile_phone_number_country_code = $mobilePhoneNumber['country-code'];

        if (!empty($Model->phone_number_country_code)) {
            $phoneNumber = $Model->phone_number_country_code.str_replace($Model->phone_number_country_code, '', $Model->phone_number);
        } else {
            $phoneNumber = $Model->phone_number;
        }
        $phoneNumber = StringHelper::explodePhoneNumber(StringHelper::normalizePhoneNumber($phoneNumber));

        $Model->phone_number = $phoneNumber['phone-number'];
        $Model->phone_number_country_code = $phoneNumber['country-code'];

    } // creating()


    /**
     * Handle the Models "deleted" event
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function deleted(TenantRecord $Model): void
    {
        //
    } // deleted()


    /**
     * Handle the Models "deleting" event
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function deleting(TenantRecord $Model): void
    {
        //
    } // deleting()


    /**
     * Handle the Models "forceDeleted" event
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function forceDeleted(TenantRecord $Model): void
    {
        //
    } // forceDeleted()


    /**
     * Handle the Models "forceDeleting" event
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function forceDeleting(TenantRecord $Model): void
    {
        //
    } // forceDeleting()


    /**
     * Handle the Models "replicating" event
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function replicating(TenantRecord $Model): void
    {
        //
    } // replicating()


    /**
     * Handle the Models "restored" event
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function restored(TenantRecord $Model): void
    {
        //
    } // restored()


    /**
     * Handle the Models "restoring" event
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function restoring(TenantRecord $Model): void
    {
        //
    } // restoring()


    /**
     * Handle the Models "retrieved" event
     *
     * The retrieved event will dispatch when an existing model is retrieved
     * from the database.
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function retrieved(TenantRecord $Model): void
    {
        //
    } // retrieved()


    /**
     * Handle the Models "saved" event
     *
     * The saving / saved events will dispatch when a model is created or
     * updated - even if the model's attributes have not been changed.
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function saved(TenantRecord $Model): void
    {
        //
    } // saved()


    /**
     * Handle the Models "saving" event
     *
     * The saving / saved events will dispatch when a model is created or
     * updated - even if the model's attributes have not been changed.
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function saving(TenantRecord $Model): void
    {
        //
    } // saving()


    /**
     * Handle the Models "trashed" event
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function trashed(TenantRecord $Model): void
    {
        //
    } // trashed()


    /**
     * Handle the Models "updated" event
     *
     * The updating / updated events will dispatch when an existing model is
     * modified and the save method is called.
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-04-14
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function updated(TenantRecord $Model): void
    {
        //
    } // updated()


    /**
     * Handle the Models "updating" event
     *
     * The updating / updated events will dispatch when an existing model is
     * modified and the save method is called.
     *
     * @param       TenantRecord $Model
     *
     * @return      void
     *
     * @version     1.1.0 / 2026-05-24
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function updating(TenantRecord $Model): void
    {
        unset($Model->uuid);

        $Model->email = StringHelper::normalizeEmail($Model->email);

        if (!empty($Model->mobile_phone_number_country_code)) {
            $mobilePhoneNumber = $Model->mobile_phone_number_country_code.str_replace($Model->mobile_phone_number_country_code, '', $Model->mobile_phone_number);
        } else {
            $mobilePhoneNumber = $Model->mobile_phone_number;
        }
        $mobilePhoneNumber = StringHelper::explodePhoneNumber(StringHelper::normalizePhoneNumber($mobilePhoneNumber));

        $Model->mobile_phone_number = $mobilePhoneNumber['phone-number'];
        $Model->mobile_phone_number_country_code = $mobilePhoneNumber['country-code'];

        if (!empty($Model->phone_number_country_code)) {
            $phoneNumber = $Model->phone_number_country_code.str_replace($Model->phone_number_country_code, '', $Model->phone_number);
        } else {
            $phoneNumber = $Model->phone_number;
        }
        $phoneNumber = StringHelper::explodePhoneNumber(StringHelper::normalizePhoneNumber($phoneNumber));

        $Model->phone_number = $phoneNumber['phone-number'];
        $Model->phone_number_country_code = $phoneNumber['country-code'];

    } // updating()


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


} // class TenantRecordObserver {}
