<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class PresenceFingerprint extends Model
{
    protected $fillable = [
        'fingerprint',
        'token',
        'expires_at',
        'socket_id',
    ];

    protected $casts = [
        'expires_at' => 'datetime',
    ];

    /**
     * Get the token that owns this fingerprint.
     */
    public function partnerToken(): BelongsTo
    {
        return $this->belongsTo(PartnerToken::class, 'token', 'token');
    }

    /**
     * Check if fingerprint is expired.
     */
    public function isExpired(): bool
    {
        return $this->expires_at->isPast();
    }

    /**
     * Check if fingerprint is active.
     */
    public function isActive(): bool
    {
        return !$this->isExpired();
    }
}
