<?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::create('media_owners', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->foreignId('organisation_id')->nullable()->constrained('organisations')->onDelete('set null');
            $table->string('business_name');
            $table->string('contact_name');
            $table->string('contact_email');
            $table->string('contact_phone')->nullable();
            $table->string('city')->default('Nairobi');
            $table->string('country')->default('Kenya');
            $table->string('kra_pin')->nullable();
            $table->string('mpesa_paybill')->nullable();
            $table->string('bank_account')->nullable();
            $table->string('bank_name')->nullable();

            // Trust & compliance
            $table->decimal('trust_score', 3, 2)->default(0.00);
            $table->unsignedInteger('total_bookings')->default(0);
            $table->unsignedInteger('proof_passed')->default(0);
            $table->unsignedInteger('proof_failed')->default(0);
            $table->unsignedInteger('disputes_lost')->default(0);
            $table->decimal('sla_compliance_rate', 5, 2)->default(0.00);

            // Status
            $table->enum('status', ['pending', 'active', 'suspended', 'banned'])->default('pending');
            $table->boolean('instant_book_eligible')->default(false);
            $table->timestamp('approved_at')->nullable();
            $table->foreignId('approved_by')->nullable()->constrained('users')->onDelete('set null');

            $table->text('notes')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });
    }

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