<?php
 namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Str; use Laravel\Sanctum\HasApiTokens; use Spatie\Permission\Traits\HasRoles; class Admin extends Authenticatable { use HasApiTokens, HasFactory, HasRoles, Notifiable, \App\Traits\SealsAdminAttributes; protected static array $sealedAdminAttributes = [ 'uuid', 'status', 'email_verified', 'is_deleted', 'is_ai_staff', 'last_login_at', 'totp_secret', 'totp_enabled', 'totp_backup_codes', 'totp_verified_at', 'notification_preferences', ]; protected $guard = 'admin'; protected $fillable = [ 'uuid', 'name', 'email', 'phone', 'password', 'status', 'email_verified', 'is_deleted', 'is_ai_staff', 'last_login_at', 'totp_secret', 'totp_enabled', 'totp_backup_codes', 'totp_verified_at', 'two_factor_method', 'two_factor_otp_hash', 'two_factor_otp_expires_at', 'two_factor_otp_sent_at', 'last_used_totp_step', 'slack_user_id', 'telegram_user_id', 'pushover_user_key', 'discord_webhook', 'teams_webhook', 'notification_preferences', ]; protected $hidden = [ 'password', 'remember_token', 'totp_secret', 'totp_backup_codes', 'two_factor_otp_hash', ]; protected $casts = [ 'email_verified' => 'boolean', 'is_deleted' => 'boolean', 'is_ai_staff' => 'boolean', 'password' => 'hashed', 'last_login_at' => 'datetime', 'totp_enabled' => 'boolean', 'totp_verified_at' => 'datetime', 'two_factor_otp_expires_at' => 'datetime', 'two_factor_otp_sent_at' => 'datetime', 'notification_preferences' => 'array', ]; protected static function boot() { parent::boot(); static::creating(function ($model) { $model->uuid = (string) Str::uuid(); }); } public function ticketDepartments() { return $this->belongsToMany(TicketDepartment::class, 'ticket_department_admins', 'admin_id', 'ticket_department_id') ->withTimestamps(); } public function balanceEntries() { return $this->hasMany(ClientBalance::class, 'admin_id'); } public function aiStaffProfile() { return $this->hasOne(AiStaffProfile::class); } public function scopeHuman($query) { return $query->where('is_ai_staff', false); } public function scopeAiStaff($query) { return $query->where('is_ai_staff', true); } public function getNotificationChannels(string $type): ?array { $prefs = $this->notification_preferences; $key = \App\Services\NotificationService::prefKey($type); if (empty($prefs) || !isset($prefs[$key])) { return null; } return $prefs[$key]; } } 