<?php

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

class CreateCsPagesTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('cs_pages')) return;

        Schema::create('cs_pages', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('site_id')->index();
            $table->unsignedInteger('business_id')->index();

            $table->string('title', 180);
            $table->string('slug', 180);
            $table->boolean('is_home')->default(false);
            $table->string('status', 20)->default('published'); // published | draft
            $table->unsignedInteger('sort')->default(0);
            $table->boolean('show_in_nav')->default(true);

            // Ordered list of section blocks: [{id,type,data{}}]
            $table->json('blocks')->nullable();

            // Per-page SEO
            $table->string('seo_title', 180)->nullable();
            $table->string('seo_description', 300)->nullable();
            $table->string('og_image_path', 255)->nullable();

            $table->timestamps();

            $table->unique(['site_id', 'slug']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('cs_pages');
    }
}
