<?php

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

/**
 * Bayi abonelik olustururken kac aylik sozlesme yapildigini girer.
 * total_price, olusturma aninda (package.monthly_fee * contract_months) olarak
 * hesaplanip anlik goruntu (snapshot) olarak saklanir; ileride paket fiyati
 * degisse bile bu aboneligin satis tutari degismez. Komisyon bu tutar uzerinden hesaplanir.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('subscriptions', function (Blueprint $table) {
            $table->unsignedInteger('contract_months')->default(1)->after('service_type')
                ->comment('Kac aylik sozlesme yapildi');
            $table->decimal('total_price', 12, 2)->nullable()->after('contract_months')
                ->comment('monthly_fee * contract_months anlik goruntusu');
        });
    }

    public function down(): void
    {
        Schema::table('subscriptions', function (Blueprint $table) {
            $table->dropColumn(['contract_months', 'total_price']);
        });
    }
};
