<?php

namespace App\Models;

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

class Employee extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = ['emp_id', 'name', 'active', 'consent_on'];

    protected function casts(): array
    {
        return [
            'active' => 'boolean',
            'consent_on' => 'date:Y-m-d',
        ];
    }

    public function faceTemplates()
    {
        return $this->hasMany(FaceTemplate::class);
    }

    public function activeFaceTemplates()
    {
        return $this->hasMany(FaceTemplate::class)->where('active', true);
    }

    public function attendanceEvents()
    {
        return $this->hasMany(AttendanceEvent::class);
    }

    public function dailyAttendance()
    {
        return $this->hasMany(DailyAttendance::class);
    }

    public function hasConsent(): bool
    {
        return $this->consent_on !== null;
    }
}
