<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;

#[Fillable(['name', 'email', 'password'])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable
{
    /** @use HasFactory<UserFactory> */
    use HasFactory, Notifiable, HasRoles;

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

    public function agentProfile()
    {
        return $this->hasOne(AgentProfile::class);
    }

    public function reports()
    {
        return $this->hasMany(Report::class);
    }

    public function assignedLeads()
    {
        return $this->hasMany(Lead::class, 'assigned_agent_id');
    }

    public function attendances()
    {
        return $this->hasManyThrough(Attendance::class, AgentProfile::class, 'user_id', 'agent_profile_id');
    }

    public function commissions()
    {
        return $this->hasManyThrough(Commission::class, AgentProfile::class, 'user_id', 'agent_profile_id');
    }
}
