<?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('orders', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            
            // Data Pengiriman (disimpan string agar kalau alamat user diubah, history order tetap asli)
            $table->string('receiver_name');
            $table->string('phone');
            $table->text('full_address');
            
            // Data Pembayaran
            $table->string('order_number')->unique(); // Contoh: VOGUE-20260329-XXXX
            $table->decimal('total_price', 15, 2);
            $table->string('payment_method'); // midtrans atau cod
            $table->string('payment_status')->default('pending'); // pending, success, failed, expired
            $table->string('snap_token')->nullable(); // Khusus Midtrans
            
            // Status Pengiriman
            $table->string('status')->default('processing'); // processing, shipping, completed, cancelled
            
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('orders');
    }
};
