<?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()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->enum('role', ['pemerintah', 'investor', 'akademisi', 'umkm', 'komunitas']);
            // $table->string('sub_sektor');
            $table->string('full_name');
            $table->string('nik')->unique();
            $table->date('birthdate');
            $table->text('address');
            $table->string('phone_number');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });


        Schema::create('pemerintah_details', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->string('institution_name');
            $table->string('foto');
            $table->text('description_pemerintah');
            $table->timestamps();
        });

        Schema::create('umkm_details', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->string('umkm_name');
            $table->string('foto');
            $table->date('establishment_date_umkm');
            $table->text('description_umkm');
            $table->string('product');
            $table->string('laporan_keuangan');
            $table->string('siup_number_umkm')->unique();
            $table->string('profit_umkm');
            $table->timestamps();
        });


        Schema::create('investor_details', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->string('foto');
            $table->string('category');
            $table->timestamps();
        });

        Schema::create('investor_personal_details', function (Blueprint $table) {
            $table->id();
            $table->foreignId('investor_details_id')->constrained('investor_details')->onDelete('cascade');
            // $table->string('foto');
            $table->string('npwp_number_inves_personal')->unique();
            $table->string('job'); // Pekerjaan
            $table->decimal('total_assets', 20, 2);
            $table->decimal('profit_inves_personal', 20, 2); //umkm, 
            $table->timestamps();
        });

        Schema::create('investor_perusahaan_details', function (Blueprint $table) {
            $table->id();
            $table->foreignId('investor_details_id')->constrained('investor_details')->onDelete('cascade');
            $table->string('company_name');
            // $table->string('foto');
            $table->date('establishment_date_inves_perusahaan');
            $table->text('description_inves_perusahaan');
            $table->string('npwp_number_inves_perusahaan')->unique();
            $table->string('siup_number_inves_perusahaan')->unique();
            $table->string('nib_number')->unique();
            $table->decimal('profit_inves_perusahaan', 20, 2);
            $table->timestamps();
        });

        Schema::create('akademisi_details', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->string('university_name');
            $table->string('foto');
            $table->text('description_akademisi');
            $table->string('faculty');
            $table->string('study_program');
            $table->string('expertise_field');
            $table->timestamps();
        });

        Schema::create('komunitas_details', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->string('community_name'); // Nama Instansi
            $table->string('foto');
            $table->date('establishment_date_komunitas');
            $table->text('description_komunitas');
            $table->string('community_license');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('komunitas_details');
        Schema::dropIfExists('akademisi_details');
        Schema::dropIfExists('investor_details');
        Schema::dropIfExists('investor_personal_details');
        Schema::dropIfExists('investor_perusahaan_details');
        Schema::dropIfExists('umkm_details');
        Schema::dropIfExists('pemerintah_details');
        Schema::dropIfExists('users');
    }
};
