<?php

namespace App\Models;

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

class User extends Authenticatable
{
    /** @use HasFactory<\Database\Factories\UserFactory> */
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'mobileno',
        'address',
        'lastname',
        'aadharcard',
        'institutecode',
        'profileimh',
        'usertype',
        'status',
        'createdby',
        'showpassword',
        'otpnumber',
        'emailotp',
        'mobilevarification',
        'emailvarify',
        'admin_failed_attempts',
        'admin_is_locked',
        'admin_locked_at',
        'password',
    ];

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

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
            'profileimh' => 'integer',
            'usertype' => 'integer',
            'status' => 'integer',
            'createdby' => 'integer',
            'otpnumber' => 'integer',
            'emailotp' => 'integer',
            'mobilevarification' => 'boolean',
            'emailvarify' => 'boolean',
            'admin_failed_attempts' => 'integer',
            'admin_is_locked' => 'boolean',
            'admin_locked_at' => 'datetime',
            'created_at' => 'datetime',
            'updated_at' => 'datetime',
        ];
    }

    public function schoolDetail(): HasOne
    {
        return $this->hasOne(SchoolDetail::class, 'schoolid');
    }

    public function studentProfile(): HasOne
    {
        return $this->hasOne(StudentProfile::class, 'studentid');
    }

    public function wallet(): HasOne
    {
        return $this->hasOne(WalletUser::class, 'userid');
    }

    public function walletHistories(): HasMany
    {
        return $this->hasMany(WalletHistory::class, 'userid');
    }

    public function gameplayHistories(): HasMany
    {
        return $this->hasMany(GameplayHistory::class, 'userid');
    }

    public function answerDetails(): HasMany
    {
        return $this->hasMany(UserAnswerDetail::class, 'createdby');
    }

    public function mobileAccessTokens(): HasMany
    {
        return $this->hasMany(MobileAccessToken::class, 'user_id');
    }

    public function deviceSessions(): HasMany
    {
        return $this->hasMany(StudentDeviceSession::class, 'user_id');
    }

    public function examSessions(): HasMany
    {
        return $this->hasMany(StudentExamSession::class, 'user_id');
    }

    public function activityLogs(): HasMany
    {
        return $this->hasMany(StudentActivityLog::class, 'user_id');
    }
}
