<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('contract_templates', function (Blueprint $table): void {
            $table->string('format', 10)->default('docx')->after('original_name')->index();
        });

        DB::table('contract_templates')->whereNull('format')->orWhere('format', '')->update(['format' => 'docx']);
    }

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