<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Device extends Model
{
    protected $connection = 'mai2';
    protected $fillable = [
        'name',
        'location',
        'ip_address',
        'port',
        'username',
        'fdid',
        'face_lib_type',
        'door_no',
        'is_device',
        'door_no',
        'is_active',
        'password',
        'last_synced_at',
        'mode',

    ];

    protected $casts = [
        'password' => 'encrypted',
        'is_active' => 'boolean',
        'last_synced_at' => 'datetime'
    ];

    // App\Models\Device
public const WORK_MODE_MAP = [
    'absen_only'  => 'passMode',
    'absen_pintu' => 'accessControlMode',
];

public function isDoorControlEnabled(): bool
{
    return $this->mode === 'absen_pintu';
}

     public function attendances()
    {
        return $this->hasMany(Attendance::class);
    }

    public function schedules()
{
    return $this->hasMany(DeviceSchedule::class);
}
}
