<?php

namespace App\Models;

use App\Traits\HasNotifications;
use Spatie\Permission\Traits\HasRoles;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use IvanSotelo\TwilioVerify\Traits\MustVerifyPhone;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use IvanSotelo\TwilioVerify\Contracts\MustVerifyPhoneContract;
// use Controlla\ConektaCashier\Billable;
// use Controlla\ConektaCashier\Contracts\Billable as BillableContract;

// example: implements MustVerifyPhoneContract, BillableContract
class User extends Authenticatable implements JWTSubject
{
    use HasRoles, HasFactory, Notifiable, HasNotifications, SoftDeletes;
    // use MustVerifyPhone
    // use Billable;

    protected $appends = [
        'home_path', 'view_permissions', 'status',
    ];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at', 'created_at'];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'avatar'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
        'verification_code',
        'roles',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function getViewPermissionsAttribute()
    {
        // get the names of the user's roles
        return $this->getRoleNames(); // Returns a collection
    }

    public function getHomePathAttribute()
    {
      return '/';
    }

    public function getStatusAttribute()
    {
      return $status = ($this->deleted_at) ? __('users.inactive') : __('users.active');
    }

    /**
     * Get the identifier that will be stored in the subject claim of the JWT.
     *
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Return a key value array, containing any custom claims to be added to the JWT.
     *
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }
}
