<?php

use App\Models\Airline;
use App\Models\Country;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function createAirline(
        string $name,
        bool $active,
        string $countryCode,
        ?string $iataCode = null,
        ?string $icaoCode = null,
        ?string $logo = null,
        ?string $internalName = null,
    ): self {
        $country = Country::where('code', $countryCode)->firstOrFail();

        $internalName = $internalName ?? Str::slug($name);
        $logo = $logo ?? $iataCode . '.png';

        Airline::create([
            'IATA_code'     => $iataCode,
            'ICAO_code'     => $icaoCode,
            'name'          => $name,
            'internal_name' => $internalName,
            'active'        => $active,
            'logo'          => $logo,
            'country_id'    => $country->id,
        ]);

        return $this;
    }


    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $this
            ->createAirline(name: 'Fly540', active: false, countryCode: 'KE', iataCode: '5H', icaoCode: 'FFV', logo: 'fly540.png')
            ->createAirline(name: 'Ansett Australia', active: false, countryCode: 'AU', iataCode: 'AN', icaoCode: 'AAA', logo: 'ansett.png')
            ->createAirline(name: 'Ansett New Zealand', active: false, countryCode: 'AU', iataCode: 'ZQ', icaoCode: 'NZA', logo: 'ansett.png')
            ->createAirline(name: 'Flight West', active: false, countryCode: 'AU', iataCode: 'YC', icaoCode: 'FWQ', logo: 'flight-west.png')
            ->createAirline(name: 'Antarctic Airways', active: true, countryCode: 'CL', iataCode: 'V5', icaoCode: 'DAP', logo: 'antarctic-airways.png')
            ->createAirline(name: 'Amaszonas Uruguay', active: false, countryCode: 'UY', iataCode: 'Z7', icaoCode: 'AUZ', logo: 'amaszonas-uruguay.png')
            ->createAirline(name: 'Amaszonas', active: false, countryCode: 'BO', iataCode: 'Z8', icaoCode: 'AZN', logo: 'amaszonas.png')
            ->createAirline(name: 'Czech Airlines', active: false, countryCode: 'CZ', iataCode: 'OK', icaoCode: 'CSA', logo: 'csa-czech-airlines.png')

        ;

    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        //
    }
};
