<?php

namespace App\Models;

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


class Worker extends Model
{
    protected $table = 'workers';
    protected $fillable = [
        'nama_pekerja',
        'tarikh_lahir',
        'no_ic_passport',
        'jantina',
        'negara_asal',
        'created_by'
    ];

    public function trainingRecords()
    {
        return $this->hasMany(TrainingRecord::class);
    }

    public function healthCheckupRecords()
    {
        return $this->hasMany(HealthCheckupRecord::class);
    }

    public function user()
    {
        return $this->belongsTo(User_Detail::class);
    }

    public function training_records()
    {
        return $this->hasMany(TrainingRecord::class);
    }

    public function health_checkup_records()
    {
        return $this->hasMany(HealthCheckupRecord::class);
    }


    public function rekodLatihan()
    {
        return $this->hasMany(TrainingRecord::class, 'worker_id');
    }

    // Relationship for health checkup records
    public function rekodKesihatan()
    {
        return $this->hasMany(HealthCheckupRecord::class, 'worker_id');
    }

    public function createdBy()
{
    return $this->belongsTo(Login::class, 'created_by');
}

}

