<?php
namespace App\Models;
use App\Enums\UserStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable { use HasApiTokens,HasFactory,Notifiable,HasRoles,SoftDeletes; protected $fillable=['merchant_id','name','email','phone','password','can_send','can_receive','status','last_login_at','last_login_ip']; protected $hidden=['password','remember_token']; protected function casts():array{return ['password'=>'hashed','can_send'=>'boolean','can_receive'=>'boolean','status'=>UserStatus::class,'last_login_at'=>'datetime'];} public function merchant():BelongsTo{return $this->belongsTo(Merchant::class);} public function effectiveCanSend():bool{return $this->merchant?->isActive() && $this->merchant->can_send && $this->can_send && $this->status===UserStatus::Active;} public function effectiveCanReceive():bool{return $this->merchant?->isActive() && $this->merchant->can_receive && $this->can_receive && $this->status===UserStatus::Active;} }
