<?php

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

class CreateContractObligationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('contract_obligations', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('user_id')->unsigned()->nullable();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->bigInteger('contract_id')->unsigned()->nullable();
            $table->foreign('contract_id')->references('id')->on('contracts')->onDelete('cascade');
            $table->bigInteger('contract_template_obligation_id')->unsigned()->nullable();
            $table->foreign('contract_template_obligation_id', 'co_cto_id')->references('id')->on('contract_template_obligations')->onDelete('cascade');
            $table->bigInteger('contract_entity_id')->unsigned()->nullable();
            $table->foreign('contract_entity_id')->references('id')->on('contract_entities')->onDelete('cascade');
            $table->string('name')->nullable();
            $table->float('sequence', 4, 2)->nullable();
            $table->string('reference')->nullable();
            $table->json('content')->nullable();
            $table->integer('must_complete')->nullable()->default(1);
            $table->integer('must_accept')->nullable()->default(1);
            $table->integer('complete_status')->nullable()->default(1);
            $table->integer('accept_status')->nullable()->default(1);
            $table->integer('type')->nullable()->default(1);
            $table->json('in_time_contract_obligation_template');
            $table->integer('status')->nullable()->default(1);
            $table->timestamp('completed_at')->nullable();
            $table->timestamp('failed_at')->nullable();
            $table->timestamp('start_at')->nullable();
            $table->timestamp('end_at')->nullable();
            $table->timestamps();
        });
    }

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