<?php #CodeGenerator V4 Δ 3ed9f5a94aacd63858b3ab64bbd95b38 Δ DYNAMICALLY GENERATED FILE - Do not modify this line! Remove it completely to protect the file from changes.
/**
 * Model Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @version     STUB: 1.5.0
 * @generated   2026-03-24 00:14:22
 * @package     bplan-base/globals
 * @subpackage  Models
 * @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\Models;


use BplanBase\Globals\Observers\LocationObserver;
use BplanBase\Globals\Scopes\TenantScope;
use BplanBase\Globals\Traits\HasActiveScope;
use BplanBase\Globals\Traits\HasNoInternalScope;
use BplanBase\Globals\Traits\HasOrderedScope;
use BplanBase\Globals\Traits\ModelHasMaterializedPath;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;


/**
 * Model Class
 *
 * @version     1.0.0 / 2026-03-24
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
#[ObservedBy([LocationObserver::class])]
class Location extends Model
{


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


    use HasActiveScope;
    use HasNoInternalScope;
    use HasOrderedScope;
    use ModelHasMaterializedPath;
    use SoftDeletes;


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


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


    /**
     * The accessors to append to the model's array form.
     *
     * @var         array<int, string> $appends
     *
     * @version     1.0.0 / 2026-03-24
     */
    protected $appends = [
        'label',
    ];


    /**
     * @var         array<string, string> $casts
     *
     * @version     1.0.0 / 2026-03-24
     */
    protected $casts = [
        'active'     => 'boolean',
        'created_at' => 'datetime',
        'deleted_at' => 'datetime',
        'internal'   => 'boolean',
        'labels'     => 'object',
        'top_level'  => 'boolean',
        'updated_at' => 'datetime',
    ];


    /**
     * The attributes that are mass assignable.
     *
     * @var         array<int, string> $fillable
     *
     * @version     1.0.0 / 2026-03-24
     */
    protected $fillable = [
        'active',
        'address_addition',
        'city',
        'coordinates',
        'direction',
        'email',
        'house_number',
        'identifier',
        'internal',
        'labels',
        'location_type_id',
        'master_id',
        'phone_number',
        'street',
        'sub_type',
        'tenant_id',
        'top_level',
        'zip_code',
    ];


    /**
     * The attributes that aren't mass assignable.
     *
     * @var         array<int, string> $guarded
     *
     * @version     1.0.0 / 2026-03-24
     */
    protected $guarded = [
        'created_at',
        'deleted_at',
        'path',
        'updated_at',
        'uuid',
    ];


    /**
     * The attributes that should be hidden for serialization.
     *
     * @var         array<int, string> $hidden
     *
     * @version     1.0.0 / 2026-03-24
     */
    protected $hidden = [];


    /**
     * The table associated with the model.
     *
     * @var         string $table
     */
    protected $table = 'locations';


    /**
     * Indicates if the model should be timestamped.
     *
     * @var         bool $timestamps
     */
    public $timestamps = true;


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


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


    /**
     *
     * @return      string|null
     *
     * @version     1.0.0 / 2026-03-24
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function getLabelAttribute(): string|null
    {
        $fallback = config('app.fallback_locale');
        $locale = \Registry::get('appLocale');

        return $this->labels->{$locale} ?? ($this->labels->{$fallback} ?? null);

    } // getLabelAttribute()


    /**
     *
     * @return      BelongsTo
     *
     * @version     1.0.0 / 2026-03-24
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function locationType(): BelongsTo
    {
        return $this->belongsTo(LocationType::class, 'location_type_id');

    } // locationType()


    /**
     *
     * @return      BelongsTo
     *
     * @version     1.0.0 / 2026-03-24
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function master(): BelongsTo
    {
        return $this->belongsTo(Location::class, 'master_id');

    } // master()


    /**
     *
     * @return      HasMany
     *
     * @version     1.0.0 / 2026-03-24
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function subLocations(): HasMany
    {
        return $this->hasMany(Location::class, 'master_id');

    } // subLocations()


    /**
     *
     * @return      BelongsTo
     *
     * @version     1.0.0 / 2026-03-24
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function tenant(): BelongsTo
    {
        return $this->belongsTo(Tenant::class, 'tenant_id');

    } // tenant()


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


    /**
     * Bootstrap the model.
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-03-24
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    protected static function booted(): void
    {
        static::addGlobalScope(new TenantScope());

    } // booted()


} // class Location extends Model {}
