<?php

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

return new class extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('account_group', function(Blueprint $table)
		{
			$table->id();
			$table->timestamps();
			$table->integer('site_id')->unsigned();
			$table->boolean('active')->default(false);

			$table->dateTime('start_at')->nullable();
			$table->dateTime('expire_at')->nullable();

			$table->integer('account_id')->unsigned();
			$table->foreign(['account_id','site_id'])->references(['id','site_id'])->on('accounts');

			$table->integer('group_id')->unsigned();
			$table->foreign(['group_id','site_id'])->references(['id','site_id'])->on('groups');

			$table->unique(['id','site_id']);
			$table->unique(['site_id','group_id','account_id']);
		});
	}

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