<?php

namespace App\Modules\Devices\Entities;

use CodeIgniter\Entity\Entity;

/**
 * Device Entity
 * 
 * Represents a device in the system.
 */
class Device extends Entity
{
    /**
     * Attributes that can be mass assigned
     * 
     * @var array<string>
     */
    protected $allowedFields = [
        'device_code',
        'device_name',
        'api_key',
        'is_active',
        'last_seen_at',
    ];

    /**
     * Attributes that should be cast to specific types
     * 
     * @var array<string, string>
     */
    protected $casts = [
        'id'          => 'integer',
        'is_active'   => 'boolean',
        'last_seen_at' => 'datetime',
        'created_at'  => 'datetime',
        'updated_at'  => 'datetime',
    ];

    /**
     * Check if device is active
     * 
     * @return bool
     */
    public function isActive(): bool
    {
        return (bool) $this->attributes['is_active'];
    }
}
