<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();

            // 1. Identitas Order & Midtrans
            $table->string('order_number')->unique();
            $table->string('snap_token')->nullable();

            // 2. Data Pembeli
            $table->foreignId('user_id')->nullable()->constrained()->onDelete('cascade');
            $table->string('customer_name');
            $table->string('customer_email');

            // 3. Data Pengiriman
            $table->string('customer_phone')->nullable();
            $table->text('customer_address')->nullable();

            // Data Wilayah
            $table->string('province_id', 10);
            $table->string('regency_id', 10);
            $table->string('district_id', 15);
            $table->string('village_id', 20)->nullable();

            // 4. Data Pembayaran & Kurir (INI YANG BARU)
            $table->decimal('total_price', 15, 2);

            // -----------------------------

            $table->string('status')->default('pending');

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

    public function down()
    {
        Schema::dropIfExists('orders');
    }
};
