<?php

namespace App\Models;

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

class AttendanceLog extends Model
{
    use HasFactory;

    protected $table = 'attendance_logs';
    
    protected $fillable = [
        'device_id',
        'card_uid',
        'event_type', // check_in, check_out, unknown
        'event_time',
        'temperature',
        'image_url',
        'raw_data',
        'processed',
        'error_message'
    ];

    protected $casts = [
        'event_time' => 'datetime',
        'temperature' => 'decimal:2',
        'processed' => 'boolean'
    ];

    public function device()
    {
        return $this->belongsTo(AttendanceDevice::class, 'device_id');
    }

    public function card()
    {
        return $this->belongsTo(SmartCard::class, 'card_uid', 'card_uid');
    }
}