<?php

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

/**
 * Class AddEmailToPracoviskaTable
 */
return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('pracoviska', function (Blueprint $table) {
            $table->string('email')->nullable()->after('nazov');
        });

        Pracovisko::query()->get()->each(function (Pracovisko $pracovisko) {
            $pracovisko->email = sprintf('%s@sekait.sk', $pracovisko->kod);
            $pracovisko->save();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('pracoviska', function (Blueprint $table) {
            $table->dropColumn('email');
        });
    }
};
