<?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::table('subscriptions', function (Blueprint $table) {
            if (!Schema::hasColumn('subscriptions', 'trial_days')) {
                $table->integer('trial_days')->default(0)->after('billing_cycle');
            }
            if (!Schema::hasColumn('subscriptions', 'trial_ends_at')) {
                $table->dateTime('trial_ends_at')->nullable()->after('trial_days');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('subscriptions', function (Blueprint $table) {
            $table->dropColumnIfExists('trial_ends_at');
            $table->dropColumnIfExists('trial_days');
        });
    }
};
