<?php

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

use App\Models\Role;

class CreateStaffProfilesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('staff_profiles', function (Blueprint $table) {
            $table->id();
            $table->string('first_name');
            $table->string('last_name');
            $table->unsignedBigInteger('user_id')->nullable();
            $table->mediumText('bio')->nullable();
            $table->string('credentials')->nullable();
            $table->string('departments')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });

        $roles = [
            'staff-profiles-manager',
        ];

        foreach ($roles as $name) {
            if (!Role::where('name', $name)->first()) {
                $role = new Role();
                $role->name = $name;
                $role->save();
            }
        }
    }

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