<?php

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

// PRC-816 — Tekrarlayan gider tanımına cost-of-sale bağı; üretilen Expense'e taşınır.
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('recurring_expenses', function (Blueprint $table) {
            $table->string('linkable_type')->nullable()->after('vendor_id');
            $table->unsignedBigInteger('linkable_id')->nullable()->after('linkable_type');
            $table->index(['linkable_type', 'linkable_id']);
        });
    }

    public function down(): void
    {
        Schema::table('recurring_expenses', function (Blueprint $table) {
            $table->dropIndex(['linkable_type', 'linkable_id']);
            $table->dropColumn(['linkable_type', 'linkable_id']);
        });
    }
};
