<?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(): void
    {
        Schema::create('promocodes', function (Blueprint $table) {
            $table->id(); // 自增主鍵
            $table->string('code', 8)->unique()->comment('優惠碼');
            $table->decimal('discount', 8, 2)->default(100)->comment('折扣金額或百分比');
            $table->enum('type', ['amount', 'percent'])->default('percent')->comment('優惠類型: 金額或百分比');
            $table->integer('usage_limit')->default(1)->comment('使用次數限制');
            $table->integer('used_count')->default(0)->comment('已使用次數');
            $table->date('valid_from')->nullable()->comment('有效期開始');
            $table->date('valid_to')->nullable()->comment('有效期結束');
            $table->boolean('is_active')->default(true)->comment('是否啟用');
            $table->string('give_to')->nullable()->comment('給予誰');
            $table->timestamps(); // 自動生成 created_at 和 updated_at
        });
    }

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