<?php

namespace App\Models;

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

class DataMustahik extends Model
{
    use HasFactory;

    protected $table = 'DataMustahik';
    protected $primaryKey = 'id_mustahik';

    protected $fillable = [
        'tanggal_pengajuan',
        'nik_kepala_kk',
        'nama_mustahik',
        'tgl_lahir',
        'no_hp',
        'status_hubungan',
        'pekerjaan',
        'pendapatan_bulanan',
        'status_kepemilikan_rumah',
        'status_kondisi_warga',
        'kategori_asnaf',
        'status',
        'catatan_amil',
        'id_masjid'
    ];

    // ==========================================
    // RELASI
    // ==========================================

    // DataMustahik terhubung ke DataKK (melalui nik_kepala_kk)
    public function kk()
    {
        return $this->belongsTo(DataKK::class, 'nik_kepala_kk', 'nik_kepala_kk');
    }

    // DataMustahik milik satu Masjid
    public function masjid()
    {
        return $this->belongsTo(Masjid::class, 'id_masjid', 'id_masjid');
    }

    // DataMustahik punya banyak riwayat distribusi zakat
    public function distribusiZakats()
    {
        return $this->hasMany(DistribusiZakat::class, 'id_mustahik', 'id_mustahik');
    }

    // DataMustahik punya banyak riwayat perubahan status (history approval)
    public function mustahikHistories()
    {
        return $this->hasMany(MustahikHistory::class, 'id_mustahik', 'id_mustahik');
    }
}
