<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Attendance extends Model
{
    protected $fillable = [
        'employee_id',
        'attendance_date',
        'check_in_at',
        'check_out_at',
        'check_in_latitude',
        'check_in_longitude',
        'check_out_latitude',
        'check_out_longitude',
        'check_in_distance_meters',
        'check_out_distance_meters',
        'late_minutes',
        'early_leave_minutes',
        'status',
        'note',
    ];

    protected $casts = [
        'attendance_date' => 'date',
        'check_in_at' => 'datetime',
        'check_out_at' => 'datetime',
        'late_minutes' => 'integer',
        'early_leave_minutes' => 'integer',
    ];

    public function employee()
    {
        return $this->belongsTo(Employee::class);
    }

    public function getLateLabelAttribute(): string
    {
        if (($this->late_minutes ?? 0) <= 0) {
            return '-';
        }

        return $this->late_minutes . ' menit';
    }

    public function getEarlyLeaveLabelAttribute(): string
    {
        if (($this->early_leave_minutes ?? 0) <= 0) {
            return '-';
        }

        return $this->early_leave_minutes . ' menit';
    }
}