<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

final class InviteCode extends Model
{
    protected $fillable = ['created_by', 'code', 'role', 'assigned_name', 'max_uses', 'used_count', 'expires_at', 'is_active'];

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

    public function available(): bool
    {
        return $this->is_active
            && $this->used_count < $this->max_uses
            && (! $this->expires_at || $this->expires_at->isFuture());
    }
}
