<?php

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

class CreateCouponTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('coupons', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->index()->nullable();
            $table->string('code', 50)->unique();
            $table->smallInteger('available_users');
            $table->smallInteger('used_count')->nullable();
            $table->enum('discount_type', ['percentage', 'value']);
            $table->float('discount_amount');
            $table->float('marketer_percentage')->nullable();
            $table->date('start_date');
            $table->date('end_date');
            $table->enum('service_type', ['all', 'consulting', 'documentation']);
            $table->boolean('status')->default(1);

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

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

            $table->engine = 'InnoDB';
        });
    }

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