<?php

namespace App\Models;

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

class TeacherAttendance extends Model
{
    use HasFactory;

    protected $table = 'teacher_attendances';
    
    protected $fillable = [
        'teacher_id',
        'date',
        'check_in_time',
        'check_out_time',
        'status', // present, absent, late, half-day, leave
        'working_hours',
        'overtime_hours',
        'remarks'
    ];

    protected $casts = [
        'date' => 'date',
        'check_in_time' => 'datetime',
        'check_out_time' => 'datetime',
        'working_hours' => 'decimal:2',
        'overtime_hours' => 'decimal:2'
    ];

    public function teacher()
    {
        return $this->belongsTo(Teacher::class);
    }

    // Calculate working hours
    public function calculateWorkingHours()
    {
        if ($this->check_in_time && $this->check_out_time) {
            $hours = $this->check_in_time->diffInHours($this->check_out_time);
            return round($hours, 2);
        }
        return 0;
    }

    // Status types
    public static function getStatusTypes()
    {
        return [
            'present' => 'উপস্থিত',
            'absent' => 'অনুপস্থিত',
            'late' => 'বিলম্বে',
            'half-day' => 'অর্ধদিবস',
            'leave' => 'ছুটি'
        ];
    }
}