<?php

use App\Services\Payments\CodAdvanceNoticeService;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        if (!DB::table('business_settings')->where('key', 'cod_advance_notice')->exists()) {
            DB::table('business_settings')->insert([
                'key' => 'cod_advance_notice',
                'value' => json_encode([
                    'status' => true,
                    'amount' => CodAdvanceNoticeService::DEFAULT_AMOUNT,
                    'notice_text' => CodAdvanceNoticeService::DEFAULT_TEXT,
                ], JSON_UNESCAPED_UNICODE),
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }
    }

    public function down(): void
    {
        DB::table('business_settings')->where('key', 'cod_advance_notice')->delete();
    }
};
