<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('rosters', function (Blueprint $table) {
            $table->unsignedBigInteger('employee_id')->nullable()->after('id');
            $table->date('duty_date')->nullable()->after('employee_id');
            $table->string('shift')->nullable()->after('duty_date');
            $table->time('starts_at')->nullable()->after('shift');
            $table->time('ends_at')->nullable()->after('starts_at');
            $table->string('duty_title')->nullable()->after('ends_at');
            $table->text('notes')->nullable()->after('duty_title');

            $table->foreign('employee_id')->references('id')->on('employees')->onDelete('set null');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('rosters', function (Blueprint $table) {
            $table->dropForeign(['employee_id']);
            $table->dropColumn([
                'employee_id',
                'duty_date',
                'shift',
                'starts_at',
                'ends_at',
                'duty_title',
                'notes',
            ]);
        });
    }
};
