<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRouletteBettingsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('roulette_bettings', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id')->index()->nullable();
            $table->unsignedBigInteger('period_id')->index()->nullable();
            $table->unsignedBigInteger('type_id')->index()->nullable();
            $table->unsignedBigInteger('betting_option_id')->index()->nullable();
            $table->string('balance')->index()->nullable();
            $table->string('result')->index()->nullable();
            $table->decimal('amount', 8, 2)->index()->default(0);
            $table->decimal('profit', 8, 2)->index()->default(0);
            $table->decimal('loss', 8, 2)->index()->default(0);
            $table->boolean('status')->index()->default(true);
            $table->timestamps();
            $table->softDeletes();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('period_id')->references('id')->on('periods')->onDelete('cascade');
            $table->foreign('type_id')->references('id')->on('roulette_types')->onDelete('cascade');
            $table->foreign('betting_option_id')->references('id')->on('roulette_betting_options')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('roulette_bettings');
    }
}
