<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Carbon;

class BlingToken extends Model
{
    use HasFactory;

    protected $table = 'bling_tokens';

    protected $fillable = [
        'access_token', 'refresh_token', 'expires_at',
    ];

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

    public function isExpired(int $skewSeconds = 60): bool
    {
        return Carbon::now()->addSeconds($skewSeconds)->greaterThanOrEqualTo($this->expires_at);
    }
}
