<?php

use App\Support\ReceiptTemplateResolver;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        if (! Schema::hasColumn('receipts', 'template')) {
            return;
        }

        $default = ReceiptTemplateResolver::resolveDefaultKey();
        DB::table('receipts')->whereNull('template')->update(['template' => $default]);
    }

    public function down(): void
    {
        //
    }
};
