<?php

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

return new class extends Migration
{
    /**
     * Tambah kolom province_code dan city_code ke tabel addresses
     * agar bisa dibandingkan dengan data toko (admin) untuk kalkulasi ongkir.
     *
     * Jalankan: php artisan migrate
     */
    public function up(): void
    {
        Schema::table('addresses', function (Blueprint $table) {
            // Cek dulu apakah kolom sudah ada agar tidak error jika dijalankan ulang
            if (!Schema::hasColumn('addresses', 'province_code')) {
                $table->string('province_code')->nullable()->after('full_address');
            }
            if (!Schema::hasColumn('addresses', 'city_code')) {
                $table->string('city_code')->nullable()->after('province_code');
            }
        });
    }

    public function down(): void
    {
        Schema::table('addresses', function (Blueprint $table) {
            $table->dropColumn(['province_code', 'city_code']);
        });
    }
};