<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Attendance extends Model
{
    protected $fillable = [
        'user_id',
        'date',
        'clock_in',
        'clock_out',
        'total_hours',
        'status',
        'in_type',
        'out_type',
        'in_note',
        'out_note',
        'approved_by',
        'work_mode',
        'break_start',
        'total_break_seconds',
        'overtime_hours',
        'anomaly_status',
        'manager_approved_by',
        'manager_approved_at',
        'admin_approved_by',
        'admin_approved_at',
        'anomaly_reason',
    ];

    protected function casts(): array
    {
        return [
            'date' => 'date',
            'clock_in' => 'datetime',
            'clock_out' => 'datetime',
            'break_start' => 'datetime',
            'total_break_seconds' => 'integer',
            'total_hours' => 'decimal:2',
            'overtime_hours' => 'decimal:2',
            'manager_approved_at' => 'datetime',
            'admin_approved_at' => 'datetime',
        ];
    }

    public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function approvedBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(User::class, 'approved_by');
    }

    public function managerApprovedBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(User::class, 'manager_approved_by');
    }

    public function adminApprovedBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(User::class, 'admin_approved_by');
    }
}
