<?php

namespace App\Modules\Clients;

use App\Models\ValidationModel;
use App\Modules\Clients\Site;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\DB;

class SiteUser extends \Eloquent
{
    use \Venturecraft\Revisionable\RevisionableTrait;

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

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['site_id', 'first_name', 'last_name', 'email', 'phone', 'mobile', 'position', 'authority', 'dynamics_id'];

    /**
     * The accessors to append to the model's array form.
     *
     * @var array
     */
    protected $appends = ['name'];

    /**
     * Get the user's full name.
     *
     * @return string
     */
    public function getNameAttribute()
    {
        return trim($this->first_name . ' ' . $this->last_name);
    }

    /**
     * Retrieves the site for this user.
     */
    public function site(): BelongsTo
    {
        return $this->belongsTo(Site::class);
    }
}
