<?php

namespace App\Filament\Traits;

use Illuminate\Support\Facades\Auth;

trait HasUserRole
{
    public bool $isTeacher = false;

    /**
     * 初始化用户角色检查
     */
    public function initializeUserRole(): void
    {
        $this->isTeacher = Auth::user()?->isTeacher() ?? false;
    }

    /**
     * 获取当前用户ID
     */
    public function getCurrentUserId(): ?int
    {
        return Auth::id();
    }

    /**
     * 获取当前老师ID（业务逻辑用）
     */
    public function getCurrentTeacherId(): ?string
    {
        return Auth::user()?->teacher?->teacher_id;
    }

    /**
     * 获取当前老师管理ID（管理界面用）
     */
    public function getCurrentTeacherManagementId(): ?int
    {
        return Auth::user()?->teacher?->id;
    }

    /**
     * 判断当前用户是否是管理员
     */
    public function isAdmin(): bool
    {
        return !$this->isTeacher;
    }

    /**
     * 判断当前用户是否是老师
     */
    public function isCurrentUserTeacher(): bool
    {
        return $this->isTeacher;
    }

    /**
     * 获取当前用户类型描述
     */
    public function getCurrentUserType(): string
    {
        return $this->isTeacher ? 'teacher' : 'admin';
    }
}
