<?php
use Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;
return new class extends Migration {public function up():void{
 Schema::table('accounts',function(Blueprint $t){$t->foreignId('merged_into_id')->nullable()->index();});
 Schema::create('renewal_opportunities',function(Blueprint $t){$t->id();$t->foreignId('business_id')->index();$t->foreignId('account_id')->index();$t->foreignId('operational_document_id')->nullable()->index();$t->foreignId('owner_id')->nullable()->index();$t->date('renewal_date');$t->decimal('value',15,2)->default(0);$t->string('status')->default('open');$t->text('notes')->nullable();$t->timestamps();});
 Schema::create('customer_health_snapshots',function(Blueprint $t){$t->id();$t->foreignId('business_id')->index();$t->foreignId('account_id')->index();$t->unsignedTinyInteger('score');$t->string('status');$t->text('notes')->nullable();$t->foreignId('recorded_by')->nullable()->index();$t->timestamps();});
 Schema::create('sla_policies',function(Blueprint $t){$t->id();$t->foreignId('business_id')->index();$t->string('priority');$t->unsignedInteger('resolution_hours');$t->boolean('active')->default(true);$t->timestamps();$t->unique(['business_id','priority']);});
 Schema::create('sla_events',function(Blueprint $t){$t->id();$t->foreignId('business_id')->index();$t->foreignId('case_id')->index();$t->foreignId('sla_policy_id')->index();$t->dateTime('due_at');$t->string('status')->default('open');$t->dateTime('breached_at')->nullable();$t->timestamps();});
 Schema::create('assignment_rules',function(Blueprint $t){$t->id();$t->foreignId('business_id')->index();$t->string('module');$t->string('strategy');$t->json('user_ids');$t->unsignedBigInteger('last_user_id')->nullable();$t->boolean('active')->default(true);$t->timestamps();});
}public function down():void{foreach(['assignment_rules','sla_events','sla_policies','customer_health_snapshots','renewal_opportunities'] as $table)Schema::dropIfExists($table);Schema::table('accounts',fn(Blueprint $t)=>$t->dropColumn('merged_into_id'));}};
