<?php

namespace App\Models;

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

class AttendanceLog extends Model
{
    use HasFactory;

    protected $fillable = [
        'machine_id',
        'raw_user_id',
        'timestamp',
        'is_processed',
    ];

    protected function casts(): array
    {
        return [
            'timestamp' => 'datetime',
            'is_processed' => 'boolean',
        ];
    }

    public function machine(): BelongsTo
    {
        return $this->belongsTo(FingerprintMachine::class, 'machine_id');
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, 'raw_user_id', 'fingerprint_pin');
    }
}
