<?php

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

class CreateSegmentosTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('segmentos', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 255);
            $table->string('image', 255)->nullable();
            $table->text('descricao')->nullable();
            $table->string('btncta'. 100)->nullable();
            $table->string('linkbtncta', 255)->nullable();
            $table->text('beneficio')->nullable();
            $table->text('features')->nullable();
            $table->text('contratacao')->nullable();
            $table->string('video', 255)->nullable();
            $table->string('linkctavideo', 255)->nullable();
            $table->timestamps();
        });

        Schema::table('segmentos', function ($table) {
            $table->softDeletes();
        });

        Schema::create('cliente_segmento', function (Blueprint $table) {
            $table->unsignedInteger('cliente_id');
            $table->unsignedInteger('segmento_id');

            $table->foreign('cliente_id')
                  ->references('id')
                  ->on('clientes')
                  ->onDelete('cascade');
            $table->foreign('segmento_id')
                  ->references('id')
                  ->on('segmentos')
                  ->onDelete('cascade');
            $table->primary(['cliente_id', 'segmento_id']);
        });

        Schema::create('faq_segmento', function (Blueprint $table) {
            $table->unsignedInteger('faq_id');
            $table->unsignedInteger('segmento_id');

            $table->foreign('faq_id')
                  ->references('id')
                  ->on('faqs')
                  ->onDelete('cascade');
            $table->foreign('segmento_id')
                  ->references('id')
                  ->on('segmentos')
                  ->onDelete('cascade');                  
            $table->primary(['faq_id', 'segmento_id']);
        });
    }

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