<?php

declare(strict_types=1);

namespace App\Models\Barangay;

use App\Models\Model;
use Hypervel\Database\Eloquent\SoftDeletes;

class Household extends Model
{
    use SoftDeletes;

    protected ?string $table = 'barangay_households';

    protected array $fillable = [
        'hashkey', 'household_no', 'head_resident_id',
        'address', 'purok', 'barangay', 'city', 'province',
        'member_count', 'ownership_type', 'monthly_rental',
        'has_electricity', 'has_water', 'housing_material',
        'is_active', 'created_by', 'updated_by',
    ];

    protected array $casts = [
        'monthly_rental'  => 'decimal:2',
        'has_electricity' => 'boolean',
        'has_water'       => 'boolean',
        'is_active'       => 'boolean',
        'member_count'    => 'integer',
    ];

    public function head()
    {
        return $this->belongsTo(Resident::class, 'head_resident_id');
    }

    public function members()
    {
        return $this->hasMany(HouseholdMember::class, 'household_id');
    }

    public function activeMembers()
    {
        return $this->members()->where('is_active', true);
    }

    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }
}
