<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('billing_profiles', function (Blueprint $table) {
            $table->string('schedule_type', 30)->default('fixed_date')->after('name');
            $table->unsignedTinyInteger('invoice_days_before')->nullable()->after('isolation_day');
            $table->unsignedTinyInteger('send_days_before')->nullable()->after('invoice_days_before');
            $table->unsignedTinyInteger('warning_days_before')->nullable()->after('send_days_before');
            $table->unsignedTinyInteger('isolation_days_after')->nullable()->after('warning_days_before');
            $table->index(['tenant_id', 'schedule_type']);
        });
    }

    public function down(): void
    {
        Schema::table('billing_profiles', function (Blueprint $table) {
            $table->dropIndex(['tenant_id', 'schedule_type']);
            $table->dropColumn([
                'schedule_type',
                'invoice_days_before',
                'send_days_before',
                'warning_days_before',
                'isolation_days_after',
            ]);
        });
    }
};
