<?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('renewals', function (Blueprint $table) {
            $table->id();

            $table->foreignId('client_id')->constrained()->restrictOnDelete();

            $table->date('contract_start_date')->nullable();
            $table->date('next_due_date');

            $table->boolean('domain_enabled')->default(false);
            $table->decimal('domain_amount', 10, 2)->nullable();

            $table->boolean('hosting_enabled')->default(false);
            $table->decimal('hosting_amount', 10, 2)->nullable();

            $table->enum('currency', ['USD', 'BOB'])->default('USD');

            $table->enum('status', ['pending', 'active', 'paid', 'cancelled'])->default('active');
            $table->date('paid_date')->nullable();
            $table->text('paid_note')->nullable();

            $table->timestamps();

            $table->index('client_id');
            $table->index('next_due_date');
            $table->index('status');
        });
    }

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