<?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_anti_addiction_records', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('age_group', 20)->default('unknown')->comment('年龄分组: child/junior_minor/senior_minor/adult/unknown');
            $table->unsignedInteger('daily_play_time')->default(0)->comment('当日游戏时长(秒)');
            $table->unsignedBigInteger('total_play_time')->default(0)->comment('累计游戏时长(秒)');
            $table->date('last_play_date')->nullable()->comment('最后游戏日期');
            $table->unsignedInteger('session_count')->default(0)->comment('当日会话数');
            $table->timestamps();
            $table->softDeletes();

            $table->unique('user_id');
            $table->index('age_group');
            $table->index('last_play_date');
        });
    }

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