<?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::create('vouchers', function (Blueprint $table) {
            $table->id();
            $table->string('code', 50)->unique();
            $table->enum('type', ['percent', 'fixed']);
            $table->decimal('value', 10, 2);                   // persentase atau nominal
            $table->decimal('min_order', 12, 2)->default(0);   // minimum subtotal untuk pakai voucher
            $table->decimal('max_discount', 12, 2)->nullable(); // cap diskon, null = tidak ada cap (hanya untuk type=percent)
            $table->unsignedInteger('quota')->nullable();       // null = unlimited
            $table->unsignedInteger('used_count')->default(0);
            $table->date('valid_from')->nullable();
            $table->date('valid_until')->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamps();
            $table->softDeletes();
        });
    }

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