<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Alumni extends Model
{
    protected $fillable = [
        'id_alumni', 
        'nama_alumni',
        'perguruan_tinggi',
        'jurusan_diambil',
        'profil_nilai',
        'profil_minat'
    ];

    protected static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            $latest = static::orderBy('id', 'desc')->first();
            if (!$latest) {
                $model->id_alumni = 'AL01';
            } else {
                $number = intval(substr($latest->id_alumni, 2)) + 1;
                $model->id_alumni = 'AL' . str_pad($number, 2, '0', STR_PAD_LEFT);
            }
        });
    }
}