<?php

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

class CreateUserSubscriptionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_subscriptions', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger("pricing_id")->nullable();
            $table->unsignedBigInteger("user_id");
            $table->unsignedBigInteger("role_id");
            $table->date("start_date")->nullable()->index();
            $table->date("end_date")->nullable()->index();
            $table->float("price")->nullable();
            $table->integer('wod_counter')->nullable();
            $table->integer('open_counter')->nullable();
            $table->integer('total_counter')->nullable();
            $table->string('name')->default("default");
            $table->string('stripe_id')->nullable()->index();
            $table->string('stripe_status')->nullable();
            $table->string('stripe_plan')->nullable();
            $table->integer('quantity')->nullable();
            $table->timestamp('trial_ends_at')->nullable();
            $table->timestamp('ends_at')->nullable();
            $table->boolean('renew')->default(false);
            $table->timestamps();

            $table->foreign("pricing_id")->references("id")->on("pricings")->onDelete("restrict");
            $table->foreign("user_id")->references("id")->on("users")->onDelete("cascade");
            $table->foreign("role_id")->references("id")->on("roles")->onDelete("restrict");
        });
    }

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