<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\Contracts\Activity;
use Spatie\Activitylog\LogOptions;

class User extends Authenticatable
{
	
  use HasFactory, Notifiable, HasRoles, HasApiTokens, LogsActivity;
  
  protected $table = 'users';

  /**
   * The attributes that are mass assignable.
   *
   * @var array<int, string>
   */
  protected $fillable = [
    'name',
	'idNumber',
	'phoneNumber',
	'organization',
	'kraPin',
    'email',
	'userId',
	'status',
    'password',
  ];
  
  public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
        ->logFillable()
		->logOnlyDirty(); //only the changed
    }
	
	public function tapActivity(Activity $activity)
    {
        $activity->table_name = "users";
    }
  
  public function matatus(): HasMany
    {
        return $this->hasMany(Matatu::class,'owner_id','id'); //'foreign_key', 'local_key'
    }

  /**
   * The attributes that should be hidden for serialization.
   *
   * @var array<int, string>
   */
  protected $hidden = [
    'password',
    'remember_token',
  ];

  /**
   * Get the attributes that should be cast.
   *
   * @return array<string, string>
   */
  protected function casts(): array
  {
    return [
      'email_verified_at' => 'datetime',
      'password' => 'hashed',
    ];
  }
}