<?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
    {
        // 템플릿에 변수 정의 JSON 추가
        Schema::table('esign_field_templates', function (Blueprint $table) {
            $table->json('variables')->nullable()->after('signer_count');
        });

        // 템플릿 필드에 변수 참조 추가
        Schema::table('esign_field_template_items', function (Blueprint $table) {
            $table->string('field_variable', 50)->nullable()->after('field_label');
        });

        // 계약에 메타데이터 JSON 추가
        Schema::table('esign_contracts', function (Blueprint $table) {
            $table->json('metadata')->nullable()->after('status');
        });

        // 계약 필드에 변수 참조 추가
        Schema::table('esign_sign_fields', function (Blueprint $table) {
            $table->string('field_variable', 50)->nullable()->after('field_label');
        });
    }

    public function down(): void
    {
        Schema::table('esign_sign_fields', function (Blueprint $table) {
            $table->dropColumn('field_variable');
        });

        Schema::table('esign_contracts', function (Blueprint $table) {
            $table->dropColumn('metadata');
        });

        Schema::table('esign_field_template_items', function (Blueprint $table) {
            $table->dropColumn('field_variable');
        });

        Schema::table('esign_field_templates', function (Blueprint $table) {
            $table->dropColumn('variables');
        });
    }
};
