<?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('users', function (Blueprint $table) {
            $table->string('phone')->nullable()->after('email');
            $table->string('company')->nullable()->after('phone');
            $table->enum('role', ['advertiser', 'agency', 'media_owner', 'admin', 'finance', 'verifier'])
                  ->default('advertiser')
                  ->after('company');
            $table->softDeletes()->after('updated_at');
        });

        Schema::create('organisations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('owner_user_id')->constrained('users')->onDelete('cascade');
            $table->string('name');
            $table->string('type')->default('advertiser');
            $table->string('email')->nullable();
            $table->string('phone')->nullable();
            $table->string('address')->nullable();
            $table->string('city')->nullable()->default('Nairobi');
            $table->string('country')->nullable()->default('Kenya');
            $table->string('kra_pin')->nullable();
            $table->boolean('is_verified')->default(false);
            $table->timestamps();
            $table->softDeletes();
        });
    }

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

        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['phone', 'company', 'role', 'deleted_at']);
        });
    }
};