<?php

namespace App\Models;

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

class Pegawai extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'pegawai'; 
    protected $primaryKey = 'id';

    protected $fillable = [
        'nip', 
        'nama', 
        'jabatan', 
        'user_id'
    ];

    // 1. Relasi ke User (Sudah ada)
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    /**
     * 2. TAMBAHKAN INI: Relasi ke Penugasan (Many-to-Many)
     * Ini supaya Pegawai tahu dia punya banyak tugas melalui tabel pivot
     */
    public function penugasan()
    {
        return $this->belongsToMany(Penugasan::class, 'penugasan_pegawai', 'pegawai_id', 'penugasan_id');
    }
}