<?php

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

class Netmails extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
		Schema::create('netmails', function (Blueprint $table) {
			$table->id();
			$table->timestamps();
			$table->softDeletes();
			$table->string('mid')->nullable();

			$table->string('to',128);
			$table->string('from',128);
			$table->string('subject',256);

			$table->dateTimeTz('datetime');
			$table->tinyInteger('tzoffset')->nullable();

			$table->tinyInteger('flags')->nullable();
			$table->tinyInteger('cost')->nullable();
			$table->string('msgid')->nullable();
			$table->string('replyid')->nullable();

			$table->text('msg');
			$table->text('msg_src')->nullable();
			$table->string('msg_crc')->nullable();

			$table->string('tagline')->nullable();
			$table->string('tearline')->nullable();
			$table->boolean('local')->default(FALSE);

			$table->string('recv_pkt')->nullable();
			$table->string('sent_pkt')->nullable();
			$table->dateTimeTz('sent_at')->nullable();

			$table->bigInteger('fftn_id');
			$table->bigInteger('tftn_id');
			$table->foreign('fftn_id')->references('id')->on('addresses');
			$table->foreign('tftn_id')->references('id')->on('addresses');
		});

		/*
		Schema::create('kludge_netmail', function (Blueprint $table) {
			$table->bigInteger('netmail_id');
			$table->string('kludge_id')->nullable();
			$table->json('value');

			$table->foreign('netmail_id')->references('id')->on('netmails');
		});
		*/

		/*
		Schema::create('netmail_path', function (Blueprint $table) {
			$table->integer('sequence');
			$table->json('value');

			$table->unique(['netmail_id','sequence']);

			$table->bigInteger('netmail_id');
			$table->foreign('netmail_id')->references('id')->on('netmails');
			$table->bigInteger('node_id');
			$table->foreign('node_id')->references('id')->on('nodes');
		});
		*/
    }

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