<?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
    {
        Schema::create('kylin_guardian_bindings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('guardian_id')->constrained('kylin_guardians')->cascadeOnDelete();
            $table->foreignId('minor_user_id')->constrained('users')->cascadeOnDelete();
            $table->string('relationship', 30)->comment('与未成年人关系');
            $table->string('status', 20)->default('active')->comment('状态: active/disabled');
            $table->json('play_limit')->nullable()->comment('游戏时间限制');
            $table->json('spending_limit')->nullable()->comment('消费限制');
            $table->json('notify_settings')->nullable()->comment('通知设置');
            $table->timestamps();
            $table->softDeletes();

            $table->index(['guardian_id', 'minor_user_id']);
            $table->index('minor_user_id');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('kylin_guardian_bindings');
    }
};
