<?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('licenses', function (Blueprint $table) {
            $table->id();
            $table->string('payment');
            $table->string('code')->unique();
            $table->boolean('used')->default(false);
            $table->string('phone')->nullable();
            $table->double('price')->nullable();
            $table->timestamp('active_date')->nullable();
            $table->timestamp('expire_date')->nullable();
            $table->string('coupon')->nullable();
            $table->boolean('disabled')->default(false);

            $table->timestamps();

            $table->unsignedBigInteger('client_id')->nullable();
            $table->unsignedBigInteger('dealer_id')->nullable();
            $table->unsignedBigInteger('application_id')->nullable();


            $table->foreign('client_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('dealer_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('application_id')->references('id')->on('applications')->onDelete('cascade');

        });
    }

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