<?php

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

return new class extends Migration {
    public function up(): void {

        Schema::table('clients', function (Blueprint $table) {
            $table->date('date_of_birth')->nullable()->change();
            $table->string('email_address')->nullable()->index()->change();
            $table->string('phone_number')->nullable()->index()->change();
            $table->string('landline')->nullable()->index()->after('phone_number');
        });
    }

    public function down(): void {
        Schema::table('clients', function (Blueprint $table) {
            $table->dropColumn('landline');
        });

        DB::table('clients')->whereNull('date_of_birth')->update(['date_of_birth' => '1900-01-01']);

        Schema::table('clients', function (Blueprint $table) {
            $table->date('date_of_birth')->nullable(false)->change();
            $table->string('email_address')->nullable(false)->unique()->change();
            $table->string('phone_number')->nullable(false)->unique()->change();
        });
    }
};
