<?php

namespace App\Models;

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

class Attendance extends Model
{
    use HasFactory;

    protected $fillable = [
        'company_id',
        'employee_id',
        'attendance_date',
        'shift_id',
        'first_in',
        'last_out',
        'total_working_hours',
        'total_break_minutes',
        'gross_minutes',
        'status'
    ];

    protected $casts = [
        'attendance_date' => 'date',
        'first_in' => 'datetime',
        'last_out' => 'datetime',
    ];

    // employee_id in this table stores users.id (employee's user_id)
    public function employee()
    {
        return $this->belongsTo(Employee::class, 'employee_id', 'user_id');
    }

    public function punchLogs()
    {
        return $this->hasMany(PunchLog::class, 'employee_id', 'employee_id')
                    ->whereColumn('attendance_date', 'attendance_date');
    }
}
