<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;

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

    protected $fillable = [
        'name',
        'email',
        'password',
        'scoala_id',
        'two_factor_enabled',
        'two_factor_secret',
        'two_factor_confirmed_at',
    ];

    public function scoala()
    {
        return $this->belongsTo(Scoala::class);
    }

    public function materii()
    {
        return $this->hasMany(Materie::class);
    }

    public function elev()
    {
        return $this->hasOne(Elev::class);
    }

    public function copii()
    {
        return $this->hasMany(Elev::class, 'parinte_user_id');
    }

    public function claseDirigentie()
    {
        return $this->hasMany(Clasa::class, 'diriginte_user_id');
    }

    protected $hidden = [
        'password',
        'remember_token',
        'two_factor_secret',
    ];

    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
            'two_factor_enabled' => 'boolean',
            'two_factor_confirmed_at' => 'datetime',
        ];
    }
}