<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ExternalApiToken extends Model
{
    protected $table = 'external_api_tokens';

    protected $fillable = [
        'provider',
        'grant_url',
        'auth_token',
        'refresh_token',
        'auth_expires_at',
        'refresh_expires_at',
    ];

    protected $casts = [
        'auth_token' => 'encrypted',
        'refresh_token' => 'encrypted',
        'auth_expires_at' => 'datetime',
        'refresh_expires_at' => 'datetime',
    ];

    public function isConnected(): bool
    {
        return $this->refresh_token !== null;
    }
}
