<?php

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

return new class extends Migration {
    public function up(): void
    {
        Schema::table('produks', function (Blueprint $table) {
            if (Schema::hasColumn('produks', 'lokasi')) {
                $table->dropColumn('lokasi');
            }

            $table->char('provinsi_code', 2)->nullable()->after('deskripsi');
            $table->char('kota_code', 4)->nullable()->after('provinsi_code');
            $table->char('kecamatan_code', 7)->nullable()->after('kota_code');
            $table->char('desa_code', 10)->nullable()->after('kecamatan_code');
        });
    }

    public function down(): void
    {
        Schema::table('produks', function (Blueprint $table) {
            $table->dropColumn(['provinsi_code', 'kota_code', 'kecamatan_code', 'desa_code']);
            $table->string('lokasi')->nullable();
        });
    }
};