<?php

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

return new class extends Migration
{
    private string $icaoCode = 'YSWS';

    public function up(): void
    {
        $region = DB::table('regions')->where('code', 'AU-NSW')->firstOrFail();

        DB::table('airports')->insert([
            'type'         => 'large_airport', // large_airport, medium_airport, small_airport, heliport, seaplane_base, balloonport, closed
            'name'         => 'Western Sydney International Airport',
            'latitude_deg' => -33.883461,
            'longitude_deg'=> 150.712981,
            'elevation_ft' => 262,
            'region_id'    => $region->id,
            'municipality' => 'Sydney',
            'icao_code'    => $this->icaoCode,
            'iata_code'    => 'WSI',
            'local_code'   => null,
            'created_at'   => now(),
            'updated_at'   => now(),
        ]);
    }

    public function down(): void
    {
        DB::table('airports')->where('icao_code', $this->icaoCode)->delete();
    }
};
