<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

#[Fillable(['name', 'email', 'password', 'role', 'nim_nidn', 'prodi', 'pts_nama', 'jenis_kelamin'])]
#[Hidden(['password', 'remember_token'])]
class User extends Authenticatable
{
    /** @use HasFactory<UserFactory> */
    use HasFactory, Notifiable;

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
        ];
    }

    public function laporans(): HasMany
    {
        return $this->hasMany(Laporan::class);
    }

    public function isMahasiswaDosen(): bool
    {
        return $this->role === 'mahasiswa_dosen';
    }

    public function isSatgas(): bool
    {
        return $this->role === 'satgas_campus'; // let's double check if we defined it as satgas_kampus or satgas_campusc in migration. Ah! The migration has 'satgas_kampus' and 'tim_penilai'.
    }

    // Let's implement getters matching migration values:
    // 'mahasiswa_dosen', 'satgas_kampus', 'tim_penilai', 'psikolog', 'rektor', 'lldikti'
    public function isMahasiswaDosenRole(): bool
    {
        return in_array($this->role, ['mahasiswa_dosen', 'mahasiswa', 'dosen']);
    }

    public function isSatgasRole(): bool
    {
        return $this->role === 'satgas_kampus';
    }

    public function isPenilaiRole(): bool
    {
        return $this->role === 'tim_penilai';
    }

    public function isPsikologRole(): bool
    {
        return $this->role === 'psikolog';
    }

    public function isRektorRole(): bool
    {
        return $this->role === 'rektor';
    }

    public function isLldiktiRole(): bool
    {
        return $this->role === 'lldikti' || $this->role === 'admin';
    }

    public function isAdmin(): bool
    {
        return $this->role === 'satgas_kampus' || $this->isLldiktiRole();
    }
}
