'integer', 'exp_year' => 'integer', 'is_default' => 'boolean', 'is_active' => 'boolean', 'metadata' => 'array', ]; // Relationships public function workspace(): BelongsTo { return $this->belongsTo(Workspace::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } // Helpers public function isCard(): bool { return $this->type === 'card'; } public function isCrypto(): bool { return $this->type === 'crypto_wallet'; } public function isBankAccount(): bool { return $this->type === 'bank_account'; } public function isExpired(): bool { if (! $this->exp_month || ! $this->exp_year) { return false; } $expiry = \Carbon\Carbon::createFromDate($this->exp_year, $this->exp_month)->endOfMonth(); return $expiry->isPast(); } public function getDisplayName(): string { if ($this->isCard()) { return sprintf('%s **** %s', ucfirst($this->brand ?? 'Card'), $this->last_four); } if ($this->isCrypto()) { return 'Crypto Wallet'; } return 'Bank Account'; } // Actions public function setAsDefault(): void { // Remove default from other methods static::where('workspace_id', $this->workspace_id) ->where('id', '!=', $this->id) ->update(['is_default' => false]); $this->update(['is_default' => true]); } public function deactivate(): void { $this->update(['is_active' => false]); } // Scopes public function scopeActive($query) { return $query->where('is_active', true); } public function scopeDefault($query) { return $query->where('is_default', true); } public function scopeForWorkspace($query, int $workspaceId) { return $query->where('workspace_id', $workspaceId); } }