<?php

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

class CreateTwitchWebhooksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('twitch_webhooks', function (Blueprint $table) {
            $table->id();
            $table->foreignId("user_id")->refereces("id")->on("users")->onUpdate("cascade")->onDelete("cascade");
            $table->enum("type", ["follow", "stream", "subscription"]);
            $table->string("topic");
            $table->string("callback");
            $table->boolean("active")->default(false);
            $table->dateTime("expires_at");
            $table->boolean("disabled")->default(false);
            $table->dateTime("disabled_at")->nullable()->default(null);
            $table->dateTime("live_since")->nullable()->default(null);
            $table->dateTime("offline_since")->nullable()->default(null);
            $table->timestamps();
            $table->unique(["user_id", "topic"]);
        });
    }

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