<?php

namespace App\Modules\Integrations\Platform\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;

class ApiToken extends Model
{
    use BelongsToTenant;

    protected $fillable = [
        'tenant_id',
        'created_by_user_id',
        'name',
        'token_hash',
        'scopes',
        'last_used_at',
        'expires_at',
        'revoked_at',
    ];

    protected $casts = [
        'scopes' => 'array',
        'last_used_at' => 'datetime',
        'expires_at' => 'datetime',
        'revoked_at' => 'datetime',
    ];

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

    public function isExpired(): bool
    {
        return $this->expires_at !== null && $this->expires_at->isPast();
    }
}

