<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SyncSession extends Model
{
    protected $table = 'sync_sessions';

    protected $fillable = [
        'organization_id',
        'user_id',
        'session_token',
        'status',
        'expires_at',
    ];

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

    public function isValid(): bool
    {
        return $this->status === 'active' && $this->expires_at->isFuture();
    }

    public function scopeActive($query)
    {
        return $query->where('status', 'active')->where('expires_at', '>', now());
    }
}
