<?php

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

use App\Models\Role;

return new class () extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('announcements', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('published_version_id')->nullable();
            $table->string('author')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });

        $roles = [
            'announcements-editor',
            'announcements-manager',
            'announcements-publisher',
        ];

        foreach ($roles as $role_name) {
            $role = new Role();
            $role->name = $role_name;
            $role->save();
        }
    }

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