<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('title', 20)->nullable()->after('id');
            $table->string('first_name')->nullable()->after('title');
            $table->string('last_name')->nullable()->after('first_name');
            $table->string('status', 20)->default('active')->after('name');
            $table->date('valid_from')->nullable()->after('status');
            $table->date('valid_until')->nullable()->after('valid_from');
            $table->foreignId('company_id')->nullable()->constrained('companies')->nullOnDelete()->after('valid_until');
            $table->string('phone', 30)->nullable()->after('company_id');
            $table->text('address')->nullable()->after('phone');
        });
    }

    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropForeign(['company_id']);
            $table->dropColumn([
                'title', 'first_name', 'last_name', 'status',
                'valid_from', 'valid_until', 'company_id', 'phone', 'address',
            ]);
        });
    }
};
