<?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('player_limits', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('type'); // deposit_daily|deposit_weekly|deposit_monthly|loss_daily|loss_weekly|loss_monthly|wager_daily|session_hours
            $table->decimal('amount', 15, 2)->nullable();
            $table->decimal('current_usage', 15, 2)->default(0);
            $table->timestamp('reset_at')->nullable();
            $table->timestamps();
            $table->unique(['user_id', 'type']);
        });

        Schema::create('self_exclusions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('period'); // 24h|7d|30d|90d|180d|365d|permanent
            $table->text('reason')->nullable();
            $table->timestamp('ends_at')->nullable(); // null = permanent
            $table->timestamp('reactivated_at')->nullable();
            $table->timestamps();
        });

        Schema::create('reality_checks', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->timestamp('session_start');
            $table->timestamp('last_check_at')->nullable();
            $table->decimal('session_bets', 15, 2)->default(0);
            $table->decimal('session_wins', 15, 2)->default(0);
            $table->integer('check_interval_minutes')->default(60);
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('reality_checks');
        Schema::dropIfExists('self_exclusions');
        Schema::dropIfExists('player_limits');
    }
};
