<?php

declare(strict_types=1);

use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Migrations\Migration;

class CreateBarangayHouseholdsTable extends Migration
{
    public function up(): void
    {
        Schema::create('barangay_households', function (Blueprint $table) {
            $table->id();
            $table->string('hashkey')->unique()->nullable();
            $table->string('household_no')->unique()->nullable();
            $table->unsignedBigInteger('head_resident_id')->nullable()->index();
            $table->string('address')->nullable();
            $table->string('purok')->nullable();
            $table->string('barangay')->nullable();
            $table->string('city')->nullable();
            $table->string('province')->nullable();
            $table->unsignedInteger('member_count')->default(0);
            $table->enum('ownership_type', ['OWNED', 'RENTED', 'SHARED'])->nullable();
            $table->decimal('monthly_rental', 10, 2)->nullable();
            $table->boolean('has_electricity')->default(false);
            $table->boolean('has_water')->default(false);
            $table->string('housing_material')->nullable();
            $table->boolean('is_active')->default(true);
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('barangay_household_members', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('household_id')->index();
            $table->unsignedBigInteger('resident_id')->index();
            $table->string('relationship_to_head')->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('barangay_household_members');
        Schema::dropIfExists('barangay_households');
    }
}
