<?php

namespace App\Models;

use Portal\Mileage\Model\Project;

use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Laravolt\Suitable\AutoFilter;
use Laravolt\Suitable\AutoSearch;
use Laravolt\Suitable\AutoSort;

class User extends \Laravolt\Platform\Models\User
{
    use AutoFilter;
    use AutoSearch;
    use AutoSort;
    use HasFactory;
    use Notifiable;

    /**
     * @var array<int, string>
     */
    protected $hidden = ['password', 'remember_token'];

    protected $fillable = ['name', 'email', 'username', 'password', 'status', 'timezone'];

    public function managedProjects(): BelongsToMany
    {
        return $this->belongsToMany(
            Project::class,
            'project_team',   // pivot table
            'pt_staff_id',    // user id column
            'fk_project_id'   // project id column
        )->withPivot('role_id')
         ->wherePivot('role_id', 1); // filter only project managers
    }

    public function aclRoles()
    {
        return $this->hasMany(\Portal\Mileage\Model\AclRoleUser::class, 'user_id', 'employeeCode');
    }

}
