<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class KartuKeluarga extends Model
{
    use HasFactory;

    protected $table = 'kartu_keluarga';

    protected $fillable = [
        'nomor_kk',
        'kepala_keluarga_id',
        'kepala_keluarga',
        'dusun_id',
        'sub_dusun_id',
        'rt',
        'rw',
        'kecamatan',
        'kabupaten',
        'provinsi',
    ];

    /**
     * Get the kepalaKeluarga that owns the KartuKeluarga
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function kepalaKeluarga(): BelongsTo
    {
        return $this->belongsTo(Penduduk::class, 'kepala_keluarga_id');
    }

    /**
     * Get the dusun that owns the KartuKeluarga
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function dusun(): BelongsTo
    {
        return $this->belongsTo(Dusun::class);
    }

    /**
     * Get all of the anggotaKeluarga for the KartuKeluarga
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function anggotaKeluarga(): HasMany
    {
        return $this->hasMany(AnggotaKartuKeluarga::class);
    }

    /**
     * Get all of the kelahiran for the KartuKeluarga
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function kelahiran(): HasMany
    {
        return $this->hasMany(Kelahiran::class);
    }
}