<?php

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

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

        Schema::create('cs_sites', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('business_id')->unique();

            // Publishing
            $table->boolean('enabled')->default(false);
            $table->string('status', 20)->default('draft'); // draft | published

            // Identity / branding
            $table->string('name', 150)->nullable();
            $table->string('tagline', 200)->nullable();
            $table->string('theme', 40)->default('aurora');
            $table->string('logo_path', 255)->nullable();
            $table->string('favicon_path', 255)->nullable();
            $table->string('og_image_path', 255)->nullable();

            // Palette / typography (theme defaults applied when null)
            $table->string('primary_color', 20)->nullable();
            $table->string('secondary_color', 20)->nullable();
            $table->string('accent_color', 20)->nullable();
            $table->string('font_heading', 80)->nullable();
            $table->string('font_body', 80)->nullable();

            // Hosting
            $table->string('subdomain_slug', 80)->nullable()->unique();
            $table->string('custom_domain', 150)->nullable()->unique();
            $table->boolean('custom_domain_verified')->default(false);

            // SEO defaults
            $table->string('seo_title', 180)->nullable();
            $table->string('seo_description', 300)->nullable();
            $table->string('analytics_id', 60)->nullable();

            // Flexible JSON blobs: contact{}, social{}, hours[], nav{header[],footer[]}, options{}
            $table->json('contact')->nullable();
            $table->json('social')->nullable();
            $table->json('hours')->nullable();
            $table->json('nav')->nullable();
            $table->json('options')->nullable();

            $table->timestamps();
        });
    }

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