<?php

use App\Models\Airline;
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
    {
        // Nullify logo for all existing AB airlines
        DB::table('airlines')
            ->where('IATA_code', 'AB')
            ->update(['logo' => null]);

        DB::table('airlines')
            ->where('IATA_code', 'AB')
            ->where('ICAO_code', 'BER')
            ->update(['active' => false]);


        DB::table('airlines')->insert([
            'IATA_code'     => 'AB',
            'ICAO_code'     => 'BNZ',
            'name'          => 'Bonza',
            'internal_name' => 'bonza',
            'country_code'  => 'AU',
            'country_name'  => 'Australia',
            'active'        => false,
            'logo'          => 'AB.png',
        ]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        DB::table('airlines')->where('internal_name', 'bonza')->delete();

        DB::table('airlines')
            ->where('IATA_code', 'AB')
            ->update(['logo' => 'AB.png']);

        DB::table('airlines')
            ->where('IATA_code', 'AB')
            ->where('ICAO_code', 'BER')
            ->update(['active' => true]);

    }
};
