<?php
/**
 * Model Class
 *
 * @version     3.0.$Revision:$
 * @version     SVN: $Id:$
 * @version     STUB: 1.6.0
 * @generated   2026-05-04 16:09:46
 * @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\Models\Location;
use BplanBase\Globals\Models\Tenant;
use BplanBase\Globals\Observers\TerminalConnectionObserver;
use BplanBase\Globals\Scopes\TenantScope;
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;


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


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


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


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


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


    /**
     * @var         array<string, string>
     *
     * @version     1.0.0 / 2026-05-04
     */
    protected $casts = [
        'connected_at'    => 'datetime',
        'created_at'      => 'datetime',
        'disconnected_at' => 'datetime',
        'updated_at'      => 'datetime',
    ];


    /**
     * The attributes that are mass assignable.
     *
     * @var         array<int, string>
     *
     * @version     1.0.0 / 2026-05-04
     */
    protected $fillable = [
        'connected_at',
        'disconnected_at',
        'location_id',
    ];


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


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


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


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


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


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


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

    } // location()


    /**
     *
     * @return      BelongsTo
     *
     * @version     1.0.0 / 2026-05-04
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    /**
     * @param       Builder $query
     *
     * @return      Builder
     *
     * @version     1.0.0 / 2026-05-04
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function scopeConnected(Builder $query): Builder
    {
        return $query->whereNull('disconnected_at');

    } // scopeConnected()


    public function tenant(): BelongsTo
    {
        return $this->belongsTo(Tenant::class, 'tenant_id');

    } // tenant()


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


    /**
     * Bootstrap the model.
     *
     * @return      void
     *
     * @version     1.0.0 / 2026-05-04
     * @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 TerminalConnection extends Model {}
