<?php

namespace App\Models;

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

class LicenseActivation extends Model
{
    use HasFactory;

    protected $fillable = [
        'license_id', 'activation_id', 'domain', 'ip_address', 'installation_id',
        'machine_fingerprint', 'server_hostname', 'os_platform', 'status',
        'activated_at', 'deactivated_at', 'last_validated_at', 'last_heartbeat_at',
        'product_version', 'activation_token', 'activation_checksum', 'meta',
    ];

    protected $casts = [
        'activated_at' => 'datetime',
        'deactivated_at' => 'datetime',
        'last_validated_at' => 'datetime',
        'last_heartbeat_at' => 'datetime',
        'meta' => 'array',
    ];

    protected $hidden = ['activation_token', 'activation_checksum'];

    public function license()
    {
        return $this->belongsTo(License::class);
    }

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