<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Intervention\Image\Colors\Rgb\Channels\Blue;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('subscriptions', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('start_date');
            $table->date('trial_end_date')->nullable();
            $table->date('end_date')->nullable();
            $table->dateTime('renewed_date')->nullable();
            $table->string('status', 45);
            $table->decimal('price', 10, 2);
            $table->smallInteger('seats')->default(1);
            $table->string('periodicity', 45)->nullable();
            $table->boolean('is_trial')->default(false);

            $table->unsignedBigInteger('account_id')->nullable();
            $table->unsignedBigInteger('subscription_plan_id')->nullable();
            $table->timestamps();

            $table->foreign('account_id')->references('id')
                ->on('accounts')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('subscription_plan_id')->references('id')
                ->on('subscription_plans')->onDelete('SET NULL')->onUpdate('CASCADE');
        });
    }

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