<?php
// app/Models/TimTeknisiPenugasan.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TimTeknisiPenugasan extends Model
{
    protected $table = 'tim_teknisi_penugasans';
    protected $primaryKey = 'id_tim_penugasan';
    
    protected $fillable = [
        'id_penugasan',
        'id_teknisi',
        'status_kehadiran',
        'catatan',
    ];
    
    protected $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];
    
    // ===================================
    // RELATIONSHIPS
    // ===================================
    
    /**
     * Relasi ke penugasan
     */
    public function penugasan()
    {
        return $this->belongsTo(Penugasan::class, 'id_penugasan', 'id_penugasan');
    }
    
    /**
     * Relasi ke teknisi
     */
    public function teknisi()
    {
        return $this->belongsTo(Teknisi::class, 'id_teknisi', 'id_teknisi');
    }
    
    // ===================================
    // HELPER METHODS
    // ===================================
    
    /**
     * Cek apakah teknisi hadir
     */
    public function isHadir(): bool
    {
        return $this->status_kehadiran === 'hadir';
    }
    
    /**
     * Cek apakah teknisi tidak hadir
     */
    public function isTidakHadir(): bool
    {
        return $this->status_kehadiran === 'tidak_hadir';
    }
    
    /**
     * Cek apakah teknisi izin
     */
    public function isIzin(): bool
    {
        return $this->status_kehadiran === 'izin';
    }
}