<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        DB::table('marriage_configs')->insertOrIgnore([
            [
                'group' => '时间规则',
                'key' => 'divorce_mutual_cooldown',
                'value' => 70,
                'label' => '协议离婚冷静期(天)',
                'description' => '协议离婚成功后，多少天内不能再次结婚 (支持设置为 0)',
                'min' => 0,
                'max' => 365,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'group' => '时间规则',
                'key' => 'divorce_auto_cooldown',
                'value' => 70,
                'label' => '系统强制离婚冷静期(天)',
                'description' => '单方面申请协议离婚但对方不管，导致超时后系统强制离婚的冷静期',
                'min' => 0,
                'max' => 365,
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ]);

        // 由于离婚有 mutual, auto, forced 等，我们同时添加 forced 参数的插入以防遗漏
        DB::table('marriage_configs')->insertOrIgnore([
            [
                'group' => '时间规则',
                'key' => 'divorce_forced_cooldown',
                'value' => 70,
                'label' => '单方强制离婚冷静期(天)',
                'description' => '通过单方面强制解除契约功能导致的离婚冷静期',
                'min' => 0,
                'max' => 365,
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ]);
    }

    public function down(): void
    {
        DB::table('marriage_configs')->whereIn('key', [
            'divorce_mutual_cooldown',
            'divorce_auto_cooldown',
            'divorce_forced_cooldown',
        ])->delete();
    }
};
