<?php
// 1. Update siswa_magang migration - add id_dudi field
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        Schema::create('siswa_magang', function (Blueprint $table) {
            $table->id();
            $table->string('nama_siswa');
            $table->enum('jk', ['L', 'P']);
            $table->string('no_telp_siswa', 15)->unique();
            $table->string('rfid_number', 50)->nullable()->unique();
            $table->unsignedBigInteger('id_sekolah');
            $table->unsignedBigInteger('id_dudi'); 
            $table->unsignedBigInteger('id_pembimbing_magang')->nullable();
            $table->unsignedBigInteger('id_pembimbing_sekolah')->nullable();
            $table->date('mulai_magang');
            $table->date('selesai_magang');
            $table->timestamps();
            
            $table->foreign('id_sekolah')->references('id')->on('sekolah')->onDelete('cascade');
            $table->foreign('id_dudi')->references('id')->on('dudi')->onDelete('cascade'); // New foreign key
            $table->foreign('id_pembimbing_magang')->references('id')->on('pembimbing_magang')->onDelete('set null');
            $table->foreign('id_pembimbing_sekolah')->references('id')->on('pembimbing_sekolah')->onDelete('set null');
        });
    }

    public function down()
    {
        Schema::dropIfExists('siswa_magang');
    }
};
