<?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
    {
        if (!Schema::hasTable('poli')) {
            Schema::create('poli', function (Blueprint $table) {
                $table->id();
                $table->string('poli', 250)->nullable();
                $table->string('subpoli', 250)->nullable();
                $table->string('subsubpoli', 250)->nullable();
                $table->string('modaliti', 150)->nullable();
                $table->string('kelompok', 150)->nullable();
                $table->string('modaliti2', 150)->nullable();
                $table->timestamp('created_at')->nullable();
                $table->timestamp('updated_at')->nullable();
            });

            return;
        }

        Schema::table('poli', function (Blueprint $table) {
            if (!Schema::hasColumn('poli', 'poli')) {
                $table->string('poli', 250)->nullable();
            }

            if (!Schema::hasColumn('poli', 'subpoli')) {
                $table->string('subpoli', 250)->nullable();
            }

            if (!Schema::hasColumn('poli', 'subsubpoli')) {
                $table->string('subsubpoli', 250)->nullable();
            }

            if (!Schema::hasColumn('poli', 'modaliti')) {
                $table->string('modaliti', 150)->nullable();
            }

            if (!Schema::hasColumn('poli', 'kelompok')) {
                $table->string('kelompok', 150)->nullable();
            }

            if (!Schema::hasColumn('poli', 'modaliti2')) {
                $table->string('modaliti2', 150)->nullable();
            }

            if (!Schema::hasColumn('poli', 'created_at')) {
                $table->timestamp('created_at')->nullable();
            }

            if (!Schema::hasColumn('poli', 'updated_at')) {
                $table->timestamp('updated_at')->nullable();
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Kolom poli dipakai data production, rollback tidak menghapus kolom.
    }
};
