<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        

        Schema::create('adat', function (Blueprint $table) {
            $table->id();

            $table->string('nama')->nullable();

            $table->foreignId('desa_kelurahan_id')->nullable()->constrained('master_desa_kelurahan');

            $table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
            $table->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null');
            $table->foreignId('deleted_by')->nullable()->constrained('users')->onDelete('set null');

            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('keluarga', function (Blueprint $table) {
            $table->id();

            $table->string('kk')->nullable();

            $table->foreignId('adat_id')->nullable()->constrained('adat');

            $table->foreignId('desa_kelurahan_id')->nullable()->constrained('master_desa_kelurahan');

            $table->string('path_kk', 500)->nullable();
            $table->string('file_kk')->nullable();

            $table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
            $table->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null');
            $table->foreignId('deleted_by')->nullable()->constrained('users')->onDelete('set null');

            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('profiles', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained();

            $table->string('role')->nullable();
            $table->string('nama');
            $table->string('email');
            $table->string('telepon')->nullable();
            $table->string('alamat')->nullable();

            $table->string('kk')->nullable();
            $table->string('ktp')->nullable();

            $table->foreignId('desa_kelurahan_id')->nullable()->constrained('master_desa_kelurahan');

            $table->string('path_kk', 500)->nullable();
            $table->string('file_kk')->nullable();
            $table->string('path_ktp', 500)->nullable();
            $table->string('file_ktp')->nullable();

            $table->foreignId('keluarga_id')->nullable()->constrained('keluarga')->onDelete('set null');

            $table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
            $table->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null');
            $table->foreignId('deleted_by')->nullable()->constrained('users')->onDelete('set null');

            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('profiles');
        Schema::dropIfExists('keluarga');
        Schema::dropIfExists('adat');
    }
};
