<?php

namespace App\Models;

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

class User extends Authenticatable
{
    use HasFactory, Notifiable, HasApiTokens, HasRoles;

    #protected $table = "IPRS_USERS";

    #const CREATED_AT = 'DATE_CREATED';
    #const UPDATED_AT = 'DATE_MODIFIED';
    #const DELETED_AT = 'D_DEL';
    #protected $primaryKey = 'id';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'id',
        'contract_rid',
        'name',
        'email',
        'status_l',
        'password',
    ];

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

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
        'password' => 'hashed',
    ];

    public function adminlte_image()
    {
        return 'images/user.svg';
    }

    public function adminlte_desc()
    {
        return "Click below to logout or view profile.";
    }

    public function adminlte_profile_url()
    {
        return 'account';
    }

    /**
     * @return BelongsTo
     */
    public function contract(): BelongsTo
    {
        //return User::find($id)->contract;
        return $this->belongsTo(Contract::class, 'contract_rid','rid');
    }

    public function payments(): HasMany
    {
        return $this->hasMany(Payments::class, 'user_id', 'id');
    }


}
