<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use App\Traits\HasPermissionsTrait;

class User extends Authenticatable
{
	use HasFactory, Notifiable, HasPermissionsTrait;

	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = [
		'id',
		'user_unique_id',
		'ip_address',
		'admin_id',
		'name',
		'email',
		'phone',
		'password',
		'user_type',
		'profile_pics',
		'school_id'
	];

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

	/**
	 * The attributes that should be cast to native types.
	 *
	 * @var array
	 */

	protected $casts = [
		'created_at' => 'datetime:Y-m-d H:i:s',
		'updated_at' => 'datetime:Y-m-d H:i:s',
	];



	public function getJWTIdentifier()
	{
		return $this->getKey();
	}
	public function getJWTCustomClaims()
	{
		return [];
	}



	public function school()
	{
		return $this->belongsToMany(School::class, 'users_schools');
	}

	public function class()
	{
		return $this->belongsToMany(Classes::class, 'users_classes_sections');
	}

	public function section()
	{
		return $this->belongsToMany(Section::class, 'users_classes_sections');
	}

	public function guardian()
	{
		return $this->belongsToMany(Guardian::class, 'guardians_users');
	}

	public function feesallot()
	{
		return $this->hasMany(Feesallotment::class, 'user_id', 'id');
	}

	public function user_admission()
	{
		return $this->belongsTo(Users_admission::class, 'user_unique_id', 'user_unique_id');
	}

	public function attendance()
	{
		return $this->hasMany(Attendance::class);
	}

	public function attendanceWithDate()
	{
		return $this->hasMany(Attendance::class);
	}


	public function permissions()
    {
        return $this->belongsToMany(Permission::class, 'users_permissions');
    }

    public function hasPermission($permission)
    {
        return $this->permissions()->where('slug', $permission)->exists();
    }





}
